Find more freelance jobs
|
You can use Do...Loop statements to run a block of code when you do not know how many repetitions you want. The block of code are repeated while a condition is true or until a condition becomes true. Repeating Code While a Condition is True You use the While keyword to check a condition in a Do...Loop statement. Do While i > 10 some code Loop Notice that if i is for example 9, the code inside the loop will never be executed. Do some code Loop While i > 10 Notice that in this example the code inside this loop will be executed at least one time, even if i is less than 10. Repeating Code Until a Condition Becomes True You use the Until keyword to check a condition in a Do...Loop statement. Do Until i = 10 some code Loop Notice that if i is equal to 10, the code inside the loop will never be executed. Do some code Loop Until i = 10 Notice that in this example the code inside this loop will be executed at least one time, even if i is equal to 10. Exiting a Do...Loop You can exit a Do...Loop statement with the Exit Do keyword. Do Until i = 10 i = i - 1 If i < 10 Then Exit Do Loop Notice that the code inside this loop will be executed as long i is different from 10, and as long as i is greater than 10. For...Next You can use For...Next statements to run a block of code when you know how many repetitions you want. |