|
|
|
|
Do/Loops· Looping is the process of repeating a series of instructions. The computer is capable of looping. · An iteration is a single execution of the statements in a loop. · Format:
· Do While | Until loops test the condition before executing the loop the first time (pretest). · Loop While | Until loops test the condition after executing the loop at least once (posttest)—Show example. Important notes1. Conditions in Do/Loops are Boolean expressions. 2. Do/Loops can be used to loop through cells in a spreadsheet until an item is found or to perform a mathematical operation until convergence occurs. They have many other uses. For/Next Loops· For/Next loops are used when you want to repeat a loop a specific number of times. The Loop Index is incremented until its specified maximum is reached. · Example:
· 3 Elements to For/Next loops: Initialize the counter, increment the counter, and test the counter to determine when it is time to terminate the loop. · Other examples:
Important notes1. Sometimes, the statements in a For/Next loop will not be executed at all. 2. You can change the loop index value, but not the test or step values. 3. It is possible to have an infinite loop. Be careful. 4. You can use the Exit For statement inside an If statement to exit the For/Next loop, even if the condition is not satisfied. |