For Loop Do Loop: Do While End While Loop Do Until Loop
For Loop Do Loop: Do While End While Loop Do Until Loop
What is a loop ?
A loop is something that goes round and round and round. If someone told you to move your finger around in a loop, you'd know what to do immediately. It is the same in Programming.
Without loop
what if you wanted to add up a thousand numbers? So a loop would make life a lot simpler. Just remember what they do: go round and round until you tell them to stop.
For Loop
Create a new Project. Add a button to your new Form. Double click your new button and type the following code for i
Do Loop
if we don't know how many times around the loop we want to go? Use for reading of text file. With a Do Loop we can use word s like While and Until.
For Loop
To sum up
A For loop needs a start position and an end position, and all on the same line A For loop also needs a way to get the next number in the loop Example:
DoWhile
1.
2.
The difference between the two is with the While ... part at the bottom, the code above it gets executed at least once. With the code on the first line after the word Do, the code might not get executed at all. After all, the number inside the variable might already be Greater Than 5. If it is, Visual Basic won't execute the code.
DoUntil
There's not much difference between the two, but a Do ... Until works like this.
DoUntil
We "Keep looping UNTIL the number in the variable called number is Less Than 5 The problem is, the number inside the variable is already Less Than 5. And if the number is Less than 5, then the code won't execute because it has already met the end condition.
DoUntil
Do
MsgBox number number = number + 1 Loop Until number >= 5 To sum up, use a Do Loop if you don't know what the end number is going to be, otherwise a For Loop might be better.