For-loop

The For-loop serves to repeat multiple times one or more commands. We will use it when we know exactly how many times an action is to be done. For example, if you would wanted to draw a crossword puzzle whose first word has 10 letters, earlier as we begin to draw, we know we will need 10 equal squares next to each other.

In order to be able to start using the For-loop, we must have the control variable of the loop (called loop counter), which evaluates the number of repetitions, where we must not forget to declare it (like variables). Before the loop command, this variable is an "ordinary" variable and can be used for any purpose. During the loop, it becomes a counter and cannot be assigned to it in any way. After the end of the loop (up to the final end) becomes again a common variable. For the proper functioning of the For-loop it is necessary to define a range of values (initial and final boundary) for which the specified command will progressively be executed.

We write the For-loop as follows:

for CV := IL to FL do command;

where:

CV - control variable (must be of ordinal type)

IL - initial limit

FL - final limit

The For-loop starts with a word for followed by the assignment of the initial (lower) value to the variable (e. g. I := 0;). To is a reserved word and means "after". The upper limit determines the maximum value of a variable I; it determines the number of times the loop is executed (e. g. 10 times). A reserved word do follows, which means "make". Finally, we will write the command to be executed. 

Vytvorte si webové stránky zdarma! Táto stránka bola vytvorená pomocou služby Webnode. Vytvorte si vlastný web zdarma ešte dnes! Vytvoriť stránky