3 Replies - 16909 Views - Last Post: 23 June 2011 - 01:11 PM Rate Topic: -----

#1 DVEENA77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 11

Nested for loop questions in VB - needed

Posted 21 June 2011 - 10:09 PM

Hi

can any one help me with different program questions in visual basic (nested for loops) to teach the students of grade 8.

thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Nested for loop questions in VB - needed

#2 nifleheim13  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 40
  • Joined: 28-February 11

Re: Nested for loop questions in VB - needed

Posted 21 June 2011 - 11:16 PM

nested for loop was almost like the nested if loop....just place a new for loop inside a for loop....do you even know how to make a simple for loop?...anyway here's a link that can help you....
http://msdn.microsof...y/5z06z1kb.aspx
Was This Post Helpful? 0
  • +
  • -

#3 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Nested for loop questions in VB - needed

Posted 22 June 2011 - 06:29 AM

Please post current code (In the code tag) regarding the issues you are having, also any errors you are encountering, and where/when do they happen.

The nested loop whether it is a do...loop or a for...next loop will process all the code in the nested loop before moving to the next parent loop, for instance:

Do Until X = 100
    For I = 0 to 10
      debug.print I
    next I
    X = X + 1
   'do more code'
Loop



so X will not progress until the I has completed what it has with its loop bounds. Then it progresses to the next X until X is 100...

Nested loops can get complex, and difficult to untangle if not done correct. ALWAYS save your project when using a new or changed loop, The end from the IDE will not work.
As far as neatness of code, I would suggest until you get better at implementing nested loops, only go a few nested loops at least until you get the hang of it. (even then I personally have never really had need to go past two-tiered nested loop, so)

And as always Best wishes, And Luck

Jesse Fender

This post has been edited by chuckjessup: 22 June 2011 - 06:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Nested for loop questions in VB - needed

Posted 23 June 2011 - 01:11 PM

Keep in mind that you use Do loops when you don't know how many times that you're going to go through the loop, and for loops when you do. When you use nested for loops, you have to have a different variable for each one:
For i = 0 to 7
    (do whatever)
    For j = 0 to 11
        (do whatever)
    Next j
    (do other stuff if you want)
Next i

This post has been edited by BobRodes: 23 June 2011 - 01:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1