While loops
In computer programming, a loop with a pre-condition is a control flow structure that repeats a set of statements while a specific condition is true before executing the loop body. This loop type is called a While
loop because the condition is checked before running the loop body. Since the loop may never execute, we say a pre-condition loop will always execute zero or more times.
While
loops with pre-conditions are helpful when you want to repeat a block of code until a specific condition is no longer true. While
loops are often used in situations where the number of times you need to repeat the loop is not known in advance. Usually, this is because the code is dependent on receiving specific input.
The basic syntax for a While
loop in VB is as follows:
While test_condition 'code to run End While
Here, test_condition
is the Boolean
expression evaluated before each loop iteration. The loop will continue executing the code block if...