Looping Structures
Looping structures let you execute a block of code multiple times. The number of times this code block is executed depends upon the type of loop used and what happens within the code block. The looping structures covered are: For Next, While, and a variety of Do loops.
For Next Loop
The For Next loop has the syntax of using the For statement followed by a variable and the start and ending range. You have to decide in advance how many times the code block gets executed.
The default loop increment is 1. Use the Step keyword to define a new increment. Terminate the For block using the Next statement. Putting the variable name after the Next statement is optional. You can prematurely exit the loop by using the Exit For statement.
While and Do Loops
Basic syntax has more variations of the looping structures than Crystal syntax. The While and Do loops all have the standard syntax. The While keyword is used to continue looping as long as the condition evaluates to True. The While block is terminated with a Wend statement.
The Do loops are terminated with a Loop statement. The Until keyword is used to continue looping when a condition evaluates to False. You can exit a Do loop with an Exit Do statement.
Code template for While … Wend:
Code template for Do While … Loop:
Code template for Do Until … Loop:
Code template for Do … Loop While:
Code template for Do … Loop Until: