Module: cycles. Loop with parameter (for)


Problem

2/17

Features of the for loop

Theory Click to read/hide

A for loop is a means of stepping through repeated actions. Let's take a closer look at how it works.

Typically, parts of a for loop perform the following steps: 
1. Set initial value. 
2. Setting the step with which the loop variable will change
3. Setting the end value.
3. Perform loop actions. 
4. Update the value(s) used in the test. 
and then steps 2-4 are repeated until the condition is met. As soon as the condition becomes false, the loop terminates and the statement following the for loop statement is executed.

Let us return to the general form of the loop statement and analyze in more detail all the parts
for *set initial value to variable* to/downto *end value* do begin
      /*one statement or block of statements - loop body*/;
end;

Setting a variable to an initial value

is responsible for setting the initial value of the cycle variable (counter), is NOT highlighted with brackets or something else
For example :
i := 0; //the cycle variable i is assigned the initial value equal to zero. With such a record,
//variable i must be declared before the loop
to/downto
This is the step at which the variable used in the loop will change. If we write to, then each iteration the value of the variable will increase by 1, if downto - decrease by 1
End value

 is the last value at which the body of the loop will still be executed. For example, if we set the last value to 100, then at 100 our loop will still be executed, and at 101 it won’t.


Let's practice writing the title of the for loop

Problem

The above program displays the numbers from 1 to 10 in a column. You can verify this by running it.
By changing the value of the loop variable from the value equal to 1 to the value equal to 10 in increments of +1, we display the value of the variable i on the screen in the body of the loop.
To pass the test, you need to make the program display all the numbers from 20 to 30 in the same column.

Change the title of the loop so that the program displays values ​​from 20 to 30