. ? , ! . : writeLn (''); 20 !!! ? ?? ? .
- , ( - !).
FOR
. , for!
. , Program, var, begin, end. : i j . :
for i := 1 to 20 do
writeLn ('!');
for _ := _ to _ do ; i, 1, - 20. ? , i = 1, 2, 3, 4, 5 ... 19, 20. .. 20 . i . ( for i := 1 to 3*65 do ....) ( for i := X + Y to X * Y / Z + 45 *j do ....). . , :
Program Test;
var
i : integer;
x : integer;
begin
x := 10;
for i := 0 to do
begin
writeLn (i, ' ', x);
x := x + 2
end
end.
:
0 10
1 12
2 14
3 16
4 18
5 20
6 22
7 24
8 26
9 28
10 30
i , ! for : (.. , , i) .
for, , " " " ". i 1 20, 20 1. :
for i := 20 downto 1 do
writeLn ('!');
i = 20, 19, ... 2, 1. . , . , .
WHILE
: while! . :
while do ;
. . :
while 1 do
writeLn ('!');
"" , .. 1 ( ). Ctrl+Break (Ctrl+C) - . if.
, While for:
i := 1;
x := 10;
while i <= x do
begin
writeLn (i, ' ', x);
x := x + 1;
i := i + 1
end;
... ? :) . , ( ) for ! . . : i = 32 757. :
i := 1;
x := 10;
while i <> x do
begin
writeLn (i, ' ', x);
x := x + 1;
i := i + 1
end;
.... ! ?? 1 1, .. i ??? . ? , .. . . ( integer) "" - 32767 ( ?). i , , . i , , .. -32767!! , x = 32 767. ? = 32767 : x + 1 = -32767 !!!! i <= x .. = 32 767 i = 32 757, + 1 = -32 767 i + 1 = 32 758 .. i <= x ! !
integer, , ! for while:
i := 1;
x := 10;
Temp := x;
while i <= Temp do
begin
writeLn (i, ' ', x);
x := x + 1;
i := i + 1
end;
temp .
...
. , : repeat-until ! while, . : repeat until ;
while:
: . . while, .
, , , , , ! while .
- :
i := 10;
repeat
writeLn (i);
i := i - 1
until i = 0;
i . .. i = 10, 9, 8 ..... 2, 1. , begin-end .. while for. , , :( ! - , . .. repeat until - .
.
- ! ? n ( n! ) n! = 1 * 2 * 3 *....* (n-1) * n - .. 1 n. :
Program Factorial;
uses CRT;
var
n, i : integer;
Result : longint;
begin
ClrScr;
Write (' ? ');
ReadLn (n);
Result := n;
for i := 0 to n do
begin
Result := Result * i
end;
writeLn (': ', Result);
ReadLn
end.
!!!! ... ??? 0? ... ... 0! . ! !
:
begin
ClrScr;
Write (' ? ');
ReadLn (n);
. ? . Ctrl+F8 ( Debug - > Add breakpoint) . ? : breakpoint (-: , :) - . , - . Debug -> Breakpoints.
, , Result. .
: writeLn (Result);
.
:) : Debug -> Add Watch Ctrl+F7 - : Result ( Watch expression) watches ( , Debug -> Watch). Result. i n. , . , (Ctrl+F9), 5 .
, : Result = 0, i = 0, n = 5. F8 ( :) Result 0 5 ( : := , :)))) ( F8)... , begin-end ( ). , :) : Result := Result * i; . (i = 0) !! ! Result 0 ! , ... 0. , Result i, i = 0 .. 0 Result 0! ! ! (Ctrl+F2). : i 1 n. , . , ( Ctrl+F8) ... ר! Result 0 !!!! ?? : ... 5... Result 5?? 1 n ??? ! Result := n; : Result := 1; !
: (Debug -> Breakpoints . Clear All) ( watches Clear All) . , : Result longint, , 31! . !