Visual Basic Fundamentals for Absolute Beginners: (09) For..Next Iterations

Play Visual Basic Fundamentals for Absolute Beginners: (09) For..Next Iterations

The Discussion

  • User profile image

    What's the difference between the use of the For..Next and Loop..Until statements?

  • User profile image

    @Shadolio: For Next is traditionally used when you want to go through a loop a specific number of times. You could accomplish the same thing in a Loop, but you'd have to declare the index variable and you'd have to increment it yourself. It does allow you some more flexibility (you could increment by 2 if a certain condition was met for example), but it also opens the door to an infinite loop if you forget to increment the counter or write your logic incorrectly. If you have a fixed number of loop iterations in mind, I'd use a For ... Next, if you want to loop until you find something or for a variable amount of time, then a Do Until ... Loop may be a better choice. Just make sure you always have a way out (if you hit the end of the file, or have been looping more than x times without hitting your expected condition, etc.)

  • User profile image

    hello seems this note with tab tab is enable by configuration i dont have it

  • User profile image

    Hi! I was just wondering, in the second example where you write this code:

    For x = 10 To 5 Step -1

    How come x doesnt have to be declared first? Is x not a variable here? Sorry, just a little confused!

Add Your 2 Cents