Turbo Pascal, although it is not a world-famous programming application, but the creators who are taking the first steps in writing software begin to get acquainted with this particular environment. It gives the concept of branches, operators, functions and procedures, as well as many other things. For example, when learning, a programmer will encounter cycles in Turbo Pascal: While, For, and Repeat.
The concept of the cycle and its variants
A cycle is called repeating actions. In this environment are used:
- with the parameter (For ... to ... do);
- with a precondition (While ... do);
- with a postcondition (Repeat ... until).
The first type is used when it is known in advance how many steps are in solving the problem. However, there are a number of tasks when there is no information about how many times certain actions will be repeated. In this case, in Pascal While the cycle becomes indispensable, as, in principle, Repeat.
Cycle structure
Pascal While, For Repeat ? . , «», , , . , , . . True, False.
, , . , , «» .
While. Pascal ABC :
1 (1 ), «» begin… end .
-
Turbo Pascal While :
- ;
- do ( Turbo Pascal Pascal ABC);
- , , False , , . . Boolean.
- . .
, . . Pascal ABC, While :
- , . . , , (True);
- False ( «»), ;
- , «» , .
While Repeat, . . .
While. - , False. , . .
?
, While Pascal . ? , . , :
, , CTRL + F2.
2 . , Continue, ( , . ). While .
Break . . .
While. Pascal . , . Pascal ABC. Turbo Pascal .
1: Y=5-X^2/2. sh=0,5 [-5;5].
:
Pascal ABC.
Turbo Pascal. .
2: , . 10 . , , . .
:
- , «» , . , , 2.
- >0, 1. - .
- summa, , 0. : .
- , . . . : , «», . . , 2.
Manual tracing is necessary in order to verify the accuracy of the calculations. Sometimes using this method you can identify errors that do not catch the eye during a routine check of the written code.
If you carry out manual calculations, you can make sure that the program works correctly. This, in turn, suggests that the algorithm for creating the code is correct, the sequence of actions leads to a logical end.