Results 1 to 3 of 3

Thread: help please, Nested loops.

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    England/northwest
    Posts
    1

    Question

    how do i use the (counter)command to do a nested loop.
    eg. for counter=1 to 10
    Print"*";
    Next counter
    How do i use an other counter to loop the program so that it prints a 10 by 10 square of *.
    Thank you for your help

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    counter isn't a command, it's a variable you use. In this case you use it to count the loops, you can use whatever variable for this purpose have as many nested loops as you want.
    Code:
      For y=1 to 10
         for x=1 to 10
            print "*";
         next x
         print 'a linefeed
      next y
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Addicted Member ender_pete's Avatar
    Join Date
    Aug 2000
    Location
    Virginia, United States
    Posts
    131
    you can't use they same variable in a nested loop because you will get the already in use error but this will do what you wanted.....

    Code:
    Dim counter, counter2, num As Integer
    
    counter = 1
    counter2 = 1
    num = 0
    
    For counter = 1 To 10
       num = num + 1
       Form1.Print num
       counter2 = 1
       For counter2 = 1 To 10
          num = num + 1
          Form1.Print num
       Next counter2
    Next counter
    [Edited by ender_pete on 11-20-2000 at 10:38 AM]
    ender_pete
    C#,VS.NET Ent Arch, vb6 ee sp5,html,vbscript,jscript,
    xml,dhtml,delphi,c++,vc++,java,cgi,php, python, ada(so ancient) ,adasage(also ancient) and others i can't remember.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width