The basis of programming is loops, for example, for. Pascal. Like any computer language, it also contains such constructs in its syntax.
Assignment of cyclic operators
– . , . , – , .
Pascal :
- for – ;
- while – ;
- repeat ... until – .
, . . for .
, :
FOR {a} := {b} TO {c} DO {d}.
, . . :
- {a} – , INTEGER;
- {b}, {c} – , , {a};
- {d} – / , .
for, Pascal {b}, {a} := {c}, :
- {b} <= {c}, ;
- {d};
- {a} , {a} := {a} + 1.
for , .
, for, , , «».
- s := 0;
- for a := 1 to 5 do
- begin
- s := s + a;
- end;
- writeln(s);
, :
- 1- : a = 1; s = 1;
- 2- : a = 2; s = 3;
- 3- : a = 3; s = 6;
- 4- : a = 4; s = 10;
- 5- : a = 5; s = 15.
«15» – 1 5.
, 1 5 .
for, Pascal {a}, {b}, {c}. , . .
- ( ) {a} .
- {b} {c} . , , 0 p. for a := 0 to pi do. – trunc() round(). , – .
- {b} < {c}, {d} .
- {a} . , {a} <> {c}. : {a} for.
- ( do) - , {a}. , .
« » : , . , 2–3 Tab.
. «» .
, f(x) = 3*x + 15, M [x1; x2], x1 x2 – . for. Pascal :
- for a := 1 to M do
- begin
- x:= x1+(x2–x1)*(a–1)/(M–1);
- f:= 3*x + 15;
- writeln (x, ‘ ’, f);
- end.
x , : x:= x1+(x2–x1)*(a–1)/(M–1).
, , for. Pascal , :
- FOR {a} := {b} TO {c} DO
- FOR {a1} := {b1} TO {c1} DO
, : . , .