loop instruction

From Lazarus wiki
Revision as of 22:27, 14 October 2020 by Rfc1394 (talk | contribs) (new article)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Pascal has three types of loop instruction, one increments a variable, and the other two test a boolean value to see if it is true. One performs the test before executing the loop, the other after executing it.


There are three kinds of loop statements, FOR, REPEAT, and WHILE. For and repeat always execute the loop at least once, and the while statement executes it zero or more times.


The For statement sets a control variable to an initial value, then perfoms the loop. at the end of the loop, the control variable is either incremented by 1 or decremented by 1 (depending on whether the loop is increasing or decreasing), and if the value of the control variable is less than the to value specified (for increasing value loops), or the control variable value is greater than the to value (for doecreasing value loops), the loop will be executed again.


The repeat statement works similarly to the for statement. The repea5 loop is executed, then a test condition is checked, and if the test result remains true, the loop is executed again.


The while statement test a condition, and if true, the loop is executed. At the end of the loop, control retuns back to the start to test if the condition is still true. The Wile loop is the only one where the loop can conceivably be executed zero times.