Cyclic ICT algorithm Pascal example. Cyclic Algorithms Types of Cycles and Cyclic Teams on Pascal

Slide 2.

Plan

Cycle concept Operator Cycle for cycle while cycle Repeat literature

Slide 3.

Literature

Kastornov A.F., Evstratova G.A. Programming language Pascal: Tutorial for universities. - Cherepovets: GOU VPO CHSU, 2010. - 117 c. - Bibliogr.: P.114. Electronic textbook on programming language Pascal /Http://pascal.guti.ru Plan

Slide 4.

Cycle concept

Algorithms for solving many tasks are cyclical, in which, to achieve the result, a certain sequence of actions is performed several times. For example, the knowledge control program displays a question, accepts the answer, adds a mark for the answer to the amount of points, then repeats these actions until the subject responds to all questions. Or, for example, to search for the desired last name in the list, check the first name of the list to match the coincidence, then the second, third, etc. As long as the desired surname is found or the end of the list will be found.

Slide 5.

The algorithm in which there is a group of operators performed several times is called cyclic. A group of repeated operators is called a cycle body. In Pascal, cycles can be implemented using for, While and Repeat cycle operators. Plan

Slide 6.

Cycle operator for

The FOR cycle operator is used if the cycle body must be performed several times, and the number of repeats is known in advance.

Slide 7.

1st form of recording operator Cycle for

The 1st form of recording Operator for Operator is generally described as follows: Forschechik: \u003d initial_treatmentTo-opposite_Dorator; Where for, to, do - service words. The meter is a variable of a sequence type (usually such as Integer), which determines the number of cycle repetitions. The number of repetitions is considered according to the formula: the final_dative is the initial_station + 1. The final_ value should be greater than or equal to the initial_name.

Slide 8.

If the cycle body consists of several operators, then the 1st form of recording of the Operator for the Operator looks like this: Forschechik: \u003d Initial_nameTo-confined_Do Begin (Cycle Body) END;

Slide 9.

Consider the algorithm for the work of the FOR cycle in the first form of recording. The counter is assigned to the initial value. Condition is checked: the counter value is greater than the final_station? If the condition is true (yes), the cycle execution ends. If the condition is false (no), the cycle body is performed, then the counter value increases by one and the conditions check again, i.e. p.

Slide 10.

2nd form of recording operator Cycle for

The 2nd form of recording Operator for Operator is generally described as follows: For counter: \u003d initial_downDOWNTO-end_dactivity. Where: For, Downto, Do - Service Words. The counter is a variable of the sequence type (usually such as Integer), which determines the number of cycle repetitions. The number of repetitions is considered by the formula: the initial_ value-finite_dation + 1. Initial_namedInteriority to be greater than or equally intended.

Slide 11.

If the cycle body consists of several operators, then the 2nd form of recording of the Operator for the operator looks like this: Forschechik: \u003d Initial_DOWNTOFO-EVENINGDO BEGIN // Body Cycle END;

Slide 12.

Consider the algorithm for the operation of the FOR cycle in the second form of recording: the counter is assigned the initial value. Condition is checked: The counter value is less than the final_station? If the condition is true (yes), the cycle execution ends. If the condition is false (no), then the cycle body is performed, then the counter value decreases per unit and the conditions check again, i.e. p.

Slide 13.

Cycle operator for

pROGRAMEX1; VAR I, N: Integer; (i - counter, n - the required number of stars) S: String; (S - the generated string line) Begin Writeln ("Enter the number of stars"); (the number of asterisks) readln (n) is requested; (the user enters the number of spars n) s: \u003d ""; (The formation of the stroke string begins with an empty string) (the string is formed along the FOR cycle. The initial_nity is meter - 1, the final_tility is the required number of spars n.) fori: \u003d 1 to n do s: \u003d s + "*"; (at each step of the cycle to the string, one asterisk) Writeln (S) is glued; (Line is displayed) ReadLN; end. Plan example: the program forms the string string. The number of stars in the string is determined by the user.

Slide 14.

While cycle

The WHILE cycle is used if the number of cycle's body repetitions during the program is unknown and can only be determined during its operation. In general, the WHILE statement is written as follows: WHILE CONDITION OF DOUPERATOR; Where While, Do - Service Words. Condition is a logical type expression that determines the continuation of the cycle.

Slide 15.

If the cycle body consists of several operators, the WHILE cycle is written as follows: Wholeboard Do Begin // Body Cycle END;

Slide 16.

Consider the algorithm of the WHILE cycle: a condition is checked. If the condition is truly, the cycle body is performed. After that, the condition is checked again. If the condition is false, the cycle is completed.

Slide 17.

Thus, when the cycle with the precondition or cycle "while" (the cycle body is still true condition). If, when you first pass the cycle, the condition will be false, the cycle body will never be fulfilled. If the condition never becomes false, the cycle will be repeated infinitely, i.e. Cold will occur.

Slide 18.

Program EX2; VaracCount: Real; (account size) MONTH: Integer; (Number of months since the opening of the account) Begin Account: \u003d 1000; (at the expense put 1000 rubles) MONTH: \u003d 0; (The account has just opened) WhileAccount

Slide 19.

Repeat cycle

The Repeat cycle, as well as the WHILE cycle, is used in the program if you need to perform a cycle body several times, but the number of repetitions is unknown in advance. In general, the Repeat cycle is written as follows: repeat // Body Cycle Until Condition; Where Repeat, Until - Service Words. Condition is a logical type expression that determines the end of the cycle.

Slide 20.

Consider the operating algorithm of the REPEAT cycle: the repeat and until cycle body is performed between the reserved words. The condition is checked. If the condition is truly, the cycle is completed. If the condition is false, the cycle body is again performed.

Slide 21.

Thus, Repet is a cycle with a post-wave or cycle "To" (the cycle body is performed to the truth of the condition). Consequently, the cycle body is performed at least once. If the condition never becomes true, the cycle will become infinite.

Slide 22.

Program EX3; VAR Time: Integer; (Delivery time) Cells: Integer; (cell number) Begin Time: \u003d 0; (cell still never started) Cells: \u003d 1; (single) Repeat Time: \u003d Time + 3; (after the next three hours) Cells: \u003d Cells * 2; (the number of cells increased by 2 times) Until Cells\u003e 24; (up to truth condition "Number of cells more than 24") Writeln (Time); (output) ReadLN; end. Factory Example: Unicellular Ameba Every 3 hours is divided into 2 cells. Determine, after how many hours the number of cells exceed 24.

See all slides

Slide 1.

Contractor Robot Cyclic Algorithm
Presentation to the informatics lesson. Grade 9 Subject: Management and Algorithms

Slide 2.

For i: \u003d 1 to n do begin action1; Action2; End;
For i: \u003d 1 to n Do Action1; Action2;
1

Slide 3.

2
While (condition True) Do Begin Action1; Action2; End;
While (condition True) do action1; Action2;

Slide 4.

3
17 cells
12 cells

Slide 5.

4
Program N1; VAR I: Integer; Begin for i: \u003d 1 to 12 do robotforw; Robotleft; For i: \u003d 1 to 17 do robotforw; Robotleft; For i: \u003d 1 to 12 do robotforw; Robotleft; For i: \u003d 1 to 17 do robotforw; Robotleft; end.
Moving down
Moving to the right
Moving up
Moving to the left
This and the following commands turn to the corner of the robot to the left

Slide 6.

5
If you put the wall, the robot will dive into it and the program will stop

Slide 7.

6
Program N2; VAR I: Integer; Begin While FreeForw Do Robotforw; Robotleft; While FreeForw do robotforw; Robotleft; While FreeForw do robotforw; Robotleft; While FreeForw do robotforw; Robotleft; end.
While ahead is free, perform a robot forward.

Slide 8.

Slide 9.

8
Program N3; VAR I: Integer; Begin for i: \u003d 1 to 4 Do Begin While FreeForw Do Robotforw; Robotleft; end; end.
Four times to move forward, until there is no obstacle and turn left

Slide 10.

9
Four times to move forward, until there is no obstacle, and turn left

Slide 11.

10
Tasks for independent work
Task 1. The left wall of the situation in an arbitrary place is put an obstacle. The robot should get to point 1 and return to its original state. Note: Use three consecutively connected cycles yet.
1
1

Slide 12.

11
Task 2. The left wall of the situation in an arbitrary place is carved. The robot should get to the cargo, take it to transport it to the warehouse and return to its original state. Note: Use two consecutively connected cycles yet.

Slide 13.

12
Task 3. The left wall of the situation in an arbitrary location is placed five cargo. The robot must all cargo to transport to the warehouse. Note: Use two sequentially connected cycles so far invested in a cycle with a parameter.

Slide 14.

13
Example 1 Robot is located in front of the entrance to the corridor. It is necessary to note all cells inside the corridor, and return back

Slide 15.

14
Program N7; Begin robotforw; While Not Freeleft Do Begin SELECT; Robotforw; end; Robotback; While Not Freeleft Do Robotback; end.
We make a step forward to enter the tunnel
While on the left there is a wall, celebrate the cage and make a step forward
Return back to the tunnel
While left wall, moving a step back

Slide 16.

15
Example 2 There are two walls supplied by an angle. The lengths of the walls are arbitrary. The robot is in the corner between the walls (see Figure). It is necessary to make a program in which the robot marks all the cells on the inside of the wall. The final position of the robot arbitrarily.

Slide 17.

16
Program N8; Begin While Not Freeright Do Begin Select; Robotforw; end; While FreeBack Do Robotback; Robotleft; While Not Freeleft Do Begin SELECT; Robotforw; end; end.
While the right is not free, I celebrate the cell and make a step forward.
Return the robot back
Turn to the left
While the left is not free, I celebrate the cell and make a step forward.

Slide 18.

Slide 19.

18
Example 3 The situation overlaps the wall that divides the situation into two parts. The wall has a passage in a cell size in an arbitrary place. It is necessary to make a program in which the robot finds this passage and goes to another part of the situation.

Slide 20.

19
Program N9; Begin robotleft; While FreeForw do robotforw; Robotright; While Not Freeleft Do Robotforw; Robotleft; Robotforw; Robotforw; end.
Turn the robot towards the wall.
We are moving forward until I do not stand in the wall
Turn the robot along the wall
Moving forward until the wall will not end
Turn the robot towards the passage
We make two steps forward, we go to another half of the situation

Description of the presentation on individual slides:

1 Slide

Slide description:

The subject of classes: "The algorithms of the cyclic structure. Programming cycles on Pascal »Discipline" Informatics "

2 Slide

Slide description:

The main concepts of the topic in this occupation are studied by the following concepts: the concept of a cycle; varieties of cyclic algorithms (cycle with precondition, cycle with postband, cycle with parameter); block diagrams of cyclic algorithms; representation of cycles operators in Pascal programming language; Applying cycles when solving problems.

3 Slide

Slide description:

The concept of a cycle When solving many tasks, one and the same sequence of actions is performed several times. For example, upon admission to educational institution The student gives the exams, while calculated by the points scored by them (variable S; its initial value S: \u003d 0;). For each exam, it receives estimates N. If the estimate is greater than "2", then S: \u003d S + N; Otherwise, stop the calculations (exit from the cycle).

4 Slide

Slide description:

The concept of cycle cycle is a sequence of operators that can be performed more than once. The cyclic algorithm is called an algorithm providing for a multiple repetition of the same action on new data. There are three types of cycle operators: cycles with precondition; Cycles with postcondition; Cycles with a meter.

5 Slide

Slide description:

Cycle with precondition. Type Cycle While While prescribes the cycle body until the condition is executed, recorded after the word flowchart with the precondition

6 Slide

Slide description:

Cycle with precondition. Type cycle While while the WHILE cycle with the above is used when the number of repetition of the cycle body is unknown in advance, and depends on the condition. If the condition is true, then the cycle body is executed, then again checking the conditions and so until the condition becomes false.

7 Slide

Slide description:

Operator Cycle with Prepala (While - While Cycle) This most commonly used repetition operator has a common view of Pascal (format): While<условие> Do.<оператор>; Here while, DO - reserved words (from English: While-in, do - do);<условие> - logical expression;<оператор> - arbitrary (possibly composite) operator.

8 Slide

Slide description:

Cycle with postband. Type cycle up to the order of the operator of the cycle with a detonation, the execution of 1-n operators is repeated until the condition becomes correct. In this cycle, the condition is verified only after the bodies of the cycle. It follows that the body always performs at least once the flowchart with the postcal

9 Slide

Slide description:

Cycle with postband. Cycle type before it is important! The cycle with the post is performed at least once independently of the condition. The undoubted convenience of the loop cycle is that inside it you can write several operators without the use of a composite operator. Conditions check is after the cycle body. Service Word Until.

10 Slide

Slide description:

Operator Cycle with postband (Type Until cycle) General view (format) Cycle operator with PASCAL PASCAL Next: REPEAT<Оператор 1>; <Оператор 2>; … <Оператор N>; Until.<условие>;

11 Slide

Slide description:

An example of the application of the operator of the cycle with the postband for the output to the screen in pairwise, the values \u200b\u200bof the variable n \u003d 1, 2, 3, 4, 5, 6, 7, 8, 9 and variable a \u003d 10, 20, 30, 40, 50, 60, 70, and 70, 80, 90 This operator will be: n: \u003d 0; REPEAT N: \u003d N + 1; A: \u003d 10 * n; Writeln (N: 2, '', A: 3); Until n\u003e \u003d 9;

12 Slide

Slide description:

Cycle with parameter. A type of type cycle with a parameter is used when you want to perform a given number of cycle steps. It should be noted that the Pascal's Pascal cycle is not too flexible (in contrast, for example, from this type of cycle in Language C). Because, on the Pascal, the cycle parameter (or counter) varies by a value equal to one. Thus, when it is required to perform a fractional step, you must use a cycle of the While type. There are two varieties of the FOR cycle: with increasing and with a decrease in the values \u200b\u200bof the meter (or parameter). Cycle block diagram with parameter (FOR cycle)

13 Slide

Slide description:

14 Slide

Slide description:

Cycle operator with parameter. Cycle type for a common view (format) of a cycle operator with the for parameter<счетчик> := <начальное значение> to.<конечное значение> Do Begin.<Операторы> end; For<счетчик> := <начальное значение> Downto.<начальное значение> Do Begin.<Операторы> end; With an increase in the meter values \u200b\u200b(parameter) with a decrease in the meter values \u200b\u200b(parameter)

15 Slide

Slide description:

Cycle operator with parameter. Cycle type for the operator that implements the cycle for - for is used if it is necessary that the program fragment repeated the specified number of times for<переменная цикла>: = <начальное значение> That<конечное значение> Do.<оператор>; Here: for, to, do - reserved words (English: for, before, execute);<счетчик (параметр) цикла> - type variable Integer, which varies on the segment from<начального значения>, increasing the unit at the end of each cycle step;<оператор> - Any (more often composite) operator.

16 Slide

Slide description:

Cycle operator with parameter. A type Cycle The FOR statement consists of a header and a cycle body. The composite operator located in the cycle body must be enclosed in BEGIN and END operator brackets. · The meter identifier is usually used "I". · The meter variable must be a sequence type. For example, integer type: Byte, Integer. · The initial and end values \u200b\u200bof the cycle parameter cannot be changed during the cycle. · The FOR Operator is used to organize cycles with fixed, in advance known or determined during the execution of the program by the number of repetitions.

17 Slide

Slide description:

The use of cycles When solving problems, each of the cycles described above can be used to program the Pascal of the same tasks with a cyclic algorithm.

18 Slide

Slide description:

Task number 1 Open the PascalaBC.NET program (integrated programs for programming programs Pascal) Save the program in the folder with your name in the system working folder PabcWork.net \\ Your_In / CIKL_1.PAS Save how ...

19 Slide

Slide description:

Task number 1 Using the cycle while (with the precondition) to make and debug a program that calculates the sum of the squares of all natural numbers from 1 to 100. Initial data: A: Integer; Result - Amount: S: Longint; Program EX1; VAR A: Integer; S: Longint; (Long integer) Begin A: \u003d 1; S: \u003d 0; (variable S to accumulate amounts) While A<=100 Do { Начало цикла – проверка условия } Begin S:=S+A*A; A:=A+1 End; Writeln(‘Вывод результата S= ’ ,S) End. Сохранить программу в папке с Вашим именем в системной рабочей папке PABCWork.NET \ Ваше_имя\Cikl_1.pas

20 Slide

Slide description:

Task 2. Delerate the cyclic structure in the Pascal language in the PascalaBC.NET Program ABC environment; VAR X, U: Integer; Begin x: \u003d 2; While X.<= 10 do begin Y:=x*x; writeln(‘вывод х: ’, x, ‘вывод у: ’, y); x:= x+2; end; end. Применить оператор цикла с предусловием для вычисления значения функции y=x2, при значениях x 2, 4, 6, 8, 10. Сохранить программу в папке с Вашим именем в системной рабочей папке PABCWork.NET \ Ваше_имя\Cikl_2.pas























Back forward

Attention! Preview slides is used exclusively for informational purposes and may not provide ideas about all presentation capabilities. If you are interested in this work, please download the full version.

Purpose: Studying the algorithmic structure of the cycles, the creation of models and algorithms for solving practical problems.

During the classes

I. Actualization of knowledge

  • Repeat the concept of the algorithm, the basic designs of the algorithmic language.
  • To be able to develop a mathematical model, the algorithm and block scheme for solving the problem.
  • Have the concept of programming languages \u200b\u200band their appointment.
  • Be able to work in the programming environment.
  • Know the structure of the program.
  • Be able to record expressions containing numeric and character values.
  • Know the structure of operators and features of their work.
  • To be able to apply operators when writing programs with linear and branching structures.
  • To be able to create and run programs for debugging.

II. Theoretical material lesson

Most practical tasks require multiple repetition of the same actions, i.e. the reuse of one or more operators. (Presentation)

Let it be necessary to enter and process the sequence of numbers. If the numbers are only five, you can make a linear algorithm. If there are thousands of them, write a linear algorithm, but very tedious and irrational. If the number of numbers by the time the algorithm is unknown, the linear algorithm is fundamentally impossible.

Another example. To find the surname of a person in the list, you need to check the first name of the list, then the second, third, etc. Until the desired or the end of the list is found or will not be found. You can overcome such difficulties with cycles.

The cycle is called a multiple executable portion of the algorithm (Programs). Accordingly, the cyclic algorithm is an algorithm containing cycles.

There are two types of cycles: with a known number of repetitions and with an unknown number of repetitions. At the same time, in both cases, there is a number of repetitions at the stage of development of the algorithm.

There are 3 types of cyclic structures:

  • Cycle with precondition;
  • Cycle with afterclination;
  • Cycle with parameter;

Otherwise, these structures are called "Until", "for" type cycles.

Graphic form of data recording algorithmic structures:

Cycle with precondition (otherwise cycle until) It looks:

condition - logical expression.

The cycle may not be executed if the value of the logical expression immediately turns out to be a lie.

Series of commands located between Begin and End are performed until so far, the condition is true .

For to the cycle end, it is necessary that the sequence of instructions between Begin and End change the value of the variables included in condition.

Cycle with postcondition (otherwise cycle before) It looks:

condition - logical expression.

Note:

Sequence of instructions between eachrepeat. anduntil will always be fulfilled at least once;

In order for the cycle to be completed, it is necessary that the sequence of operators betweenrepeat. anduntil Changed the values \u200b\u200bof the variables included in the expression condition.

The Repeat instruction, as well as the WHILE instruction, is used in the program, if you need to conduct some repetitive calculations (cycle), but the number of repetition is not known in advance and is determined by the number of calculation itself.

Cycle with a parameter (otherwise cycle for) It has the form:

i - cycle parameter;
a - the initial value of the cycle;
b - the final value of the cycle;
h is a parameter change step.

The structure of this cycle is otherwise called cycle I times.

This command is done in this way: the parameter i is assigned the initial value A is compared with the final value B and, if it is less than or equal to the final value B, a series of commands is performed. The parameter is assigned the value of the previous, enlarged h. - Steps of changes in the parameter and again compared with the final value b.

In the programming language, Pascal, the parameter change step can be equal to one or minus one.

If only one operator is between Begin and End, the operator brackets can not write. This rule works for a "yet" and "for" type cycle.

Consider an example of solving tasks using these structures.

Example.

Calculate the product of numbers from 1 to 5 using various cycle options.

Mathematical model:

P \u003d 1 · 2 · 3 · 4 · 5 \u003d 120

Let's make an algorithm in the form of a flowchart.

To verify the correctness of the algorithm, fill the trace table.

Step Operation R i. Checking condition
1 P: \u003d 1 1
2 i: \u003d 1; 1 1
3 i.<=5
P: \u003d P * I
I: \u003d i + 1
1 1 1<=5, да (истина)
4 i.<=5
P: \u003d P * I
I: \u003d i + 1
2 2 2<=5, да (истина)
5 i.<=5
P: \u003d P * I
I: \u003d i + 1
6 3 3<=5, да (истина)
6 i.<=5
P: \u003d P * I
I: \u003d i + 1
24 4 4<=5, да (истина)
7 i.<=5
P: \u003d P * I
I: \u003d i + 1
120 5 5<=5, да (истина)
8 i.<=5
P: \u003d P * I
I: \u003d i + 1
6<=5, нет (ложь)

Verification Conditions occur in several steps: checking the terms and execution of commands on one of the branches. Therefore, the trace table does not record the algorithm commands, but separate operations performed by the computer at each step.

Step one: P is assigned a value one.

Step two: i is assigned to one.

Step Third: at i equal unit checking the condition alone less than or equal to five, yes, the condition is true, it means that the value of one multiplied to one will be two. For I: one plus one, there will be two.

Step four:at i equal to two, the condition is currently less than or equal to five, yes, the condition is true, it means that the value of 2 multiplied to one, will be 2. for i: two plus one, there will be three.

Pitch Fifth:at i equal to three, we check the condition three less or equal to five, yes, the condition is true, which means P assigns the value of two multiplied by three, there will be six. For i: Three plus one, there will be four.

Step Six:at i equal to four, the condition is four less or equal to five, yes, the condition is true, it means that the value of six multiplied by four will be twenty-four. For I: Four plus one, there will be five.

Step seventh:for i equal to five, the condition is five less or equal to five, yes, the condition is true, it means that the value of twenty four multiplied by five will be one hundred and twenty. For I: Five plus one, there will be six.

Step eighth:at i equal to six, the condition is six less or equal to five, no, the condition is false, then we leave the cycle, and as a result we obtain the last value equal to one hundred and twenty.

Program PR1;
VAR I: Integer;
Begin.
P: \u003d 1;
i: \u003d 1;
While I.<=5 do
Begin.
P: \u003d p * i;
i: \u003d i + 1;
end;
Write ('p \u003d', p);
end.

For a cycle with a deselation, we construct a block diagram and trace table. (slide16)

As a result, we get the last value equal to one hundred twenty at the seventh step

And for a cycle with a parameter, we build a block diagram and trace table. (slide17)

As a result, we get the last value equal to one hundred twenty on the sixth step

A task:

Display numbers from 1 to 5 V:

  1. straightforward;
  2. reverse order.

Mathematical model:

  1. 1 2 3 4 5;
  2. 5 4 3 2 1.

The block diagram and the problem of solving the problem is presented for numbers in direct and reverse order.

(Slide 21)

We record the considered algorithms in the programming language Pascal.

(Slide 22)

III. Summing up the lesson

And so we reviewed the following questions:

  1. Algorithmic structure cycle;
  2. Types of algorithmic structures:
    1. Cycle with precondition;
    2. Cycle with afterclination;
    3. Cycle with parameter;
  3. Considered ways to write these structures;
  4. Disassembled examples of solving problems with the help of these structures.

Cyclic algorithms06.04.2017
Cyclic algorithms
Types of cycles and cyclic
Teams on Pascal

Cycle is repeated
Repetition of sequence
action
Repeating part of the algorithm
called cycle body
Types of cycles
With a given number
Repetitions
Terms condition
cycle
With condition
The exit condition is
cycle

Types of cycles (content)
Cycle with precondition
Practice
Cycle with postband
Practice
Cycle with parameters
Practice
Solution of complex tasks

Cycle with precondition

Practice

condition and the action that needs to be performed only
After checking the conditions use the cycle in the precondition.


Before each execution of the cycle body is checked
conditions, if the result of "truth", then the cycle body is performed
Once again, if "lie", then there is a way out of the cycle.
On the block - scheme
Start cycle
Not
Condition
YES
Cycle body
End of cycle
In Pascal.
While<условие> do.
Begin.
<тело цикла>
end;

Cycle with postband

Practice
If the number of repetitions is unknown in advance, but only specified
condition and the action that must be done before
Condition checks use cycle with postcal.
As a condition, a logical expression is used, body
Cycle is a simple or composite operator.
After each execution of the cycle body, checks
conditions if the result is "false", then the cycle body is performed
Once again, if the "truth", then there is a way out of the cycle.
On the block - scheme
In Pascal.
Repeat.
Cycle body
<тело цикла>
Yes
Not
Condition
Until<условие>;

Cycle with parameter

Practice
Cycle with parameter
In cases where the number of repetitions is known in advance
A cycle is used in the parameter.
A variable specifying the number of repetitions is called
The cycle parameter or control variable.
After each body execution cycle managing
The variable increases or decreases, cycle
It is run until it is time until it exceeds either
will be less limitations.
On the block - scheme
In Pascal.
For x: \u003d a to b doo
X: \u003d A, B, C
Cycle body
X - control variable (cycle parameter)
A - initial meaning x, in - finite x
C - a step of change x
Begin.
<тело цикла>
End;
As a step you can use
only:
"To" \u003d 1;
"Downto" \u003d -1

Example of a task using a cycle with a precondition
Theory

Sliver algorithm:
Multiply the number x is initially equal to 1
The specified number of times (H) is 3.
Start
PROGRAMM STEPEN;
Var.
H, B, X: Integer;
Begin.
Writeln ('degree?' ');
Readln (h);
X: \u003d 1;
B: \u003d 1;
While B.<=H do
Begin.
X: \u003d x * 3;
B: \u003d b + 1;
End;
Writeln ('result', x);
End.
Pascal
N.
Enter a given degree
X: \u003d 1
Initial values
B: \u003d 1
Not
"B" degree counter
B≤h.
Yes
X: \u003d x * 3
Multiplication by 3.
B \u003d in + 1
Increase meter
H.
The derocation of the received
Values
end
Block diagram
Explanations

An example of a task using a cycle with a postcal
Theory
Task: raise the number 3 in a given degree
Sliver algorithm:

PROGRAMM STEPEN;
Var.
H, B, X: Integer;
Begin.
Writeln ('degree?' ');
Readln (h);
X: \u003d 1;
B: \u003d 0;
Repeat.
X: \u003d x * 3;
B: \u003d b + 1;
Not
Until b\u003e \u003d H;
Writeln ('result', x);
End.
Start
N.
Enter a given degree
X: \u003d 1
Initial values
B: \u003d 0
Multiplication by 3.
X: \u003d x * 3
Increase meter
B \u003d in + 1
Yes
B\u003e \u003d H
"B" degree counter
H.
The derocation of the received
Values
end
Pascal
Block diagram
Explanations

An example of a task using a cycle with a parameter
Theory
Task: raise the number 3 in a given degree
Sliver algorithm:
Multiply the number x is initially equal to 1 specified number of times (H) by 3.
PROGRAMM STEPEN;
Var.
H, B, X: Integer;
Begin.
Writeln ('degree?' ');
Readln (h);
X: \u003d 1;
For b: \u003d 1 to h doo
Begin.
X: \u003d x * 3;
End;
Writeln ('result', x);
End.
Pascal
Start
N.
X: \u003d 1
B: \u003d 1, H, 1
X: \u003d x * 3
H.
end
Block diagram
Enter a given degree
The initial value x \u003d 1
Parameters from 1 BC
Multiplication by 3.
The derocation of the received
Values
Explanations

The selection of the cycle depends on the characteristics of the problem. Only practice will tell you the optimal solution.

Task: Starting training, athlete on the first day
ran 10 km. Every day he increased daylight
Norma for 10% of the norm of the previous day.
What a total path runs athlete for 7 days.
Input variables:
d - number of days
SD - Distance for Current Day
Output variables:
S - shared way

Block - scheme to solve

start
S: \u003d 10
SD: \u003d 10
D: \u003d 1
D: \u003d D + 1
SD: \u003d SD * 1.1
S: \u003d S + SD
not
D \u003d 7.
Yes
S.
end

Program on Pascal

Cycle "for"
Cycle "While"
Cycle "before"
Program Beg;
Program Beg;
Program Beg;
Var.
Var.
Var.
S, SD: REAL;
S, SD: REAL;
S, SD: REAL;
D: BYTE;
D: BYTE;
D: BYTE;
Begin.
Begin.
Begin.
S: \u003d 10;
S: \u003d 10;
S: \u003d 10;
SD: \u003d 10;
SD: \u003d 10;
SD: \u003d 10;
For d: \u003d 2 to 7 Do
Begin.
While D.<7 do
Begin.
Repeat.
D: \u003d D + 1;
SD: \u003d 1.1 * SD;
D: \u003d D + 1;
SD: \u003d 1.1 * SD;
S: \u003d S + SD;
SD: \u003d 1.1 * SD;
S: \u003d S + SD;
end;
S: \u003d S + SD;
Until (d \u003d 7);
Writeln ('s \u003d', s);
end;
Writeln ('s \u003d', s);
End.
Writeln ('s \u003d', s);
End.
End.

Questions for control:
1. What operator in Pascal is set cycle with
Provote
2. As in the cycle in the parameter indicate the step "1" and "-1"
3. What branch comes from the cycle with
postcondition
4. Is there a cycle with the condition parameter
5. What could be the cycle body
6. When the cycle is used with parameters
the end