Programming in PASCAL : Iteration / PDF


Programming in PASCAL : Iteration / PDF





Programming in PASCAL : Iteration / PDF





Sample of the PDF document 




Introduction

Iteration, also known as repetition or looping, is another important construct in any procedural language.  Nearly all problem solutions require some means of repeating blocks of code.  There are three constructs that can be used for repetition:
Ø  The FOR loop
Ø  The WHILE loop
Ø  The REPEAT UNTIL loop

The FOR Loop

This is essentially a counter controlled loop where a block of code is repeated a number of times.  The FOR statement includes:
Ø  The initialisation of the counter variable
Ø  The setting of the final value of the counter
Ø  The value that the counter variable will be incremented by as each loop is executed.

The FOR loop takes the form:
for counter_variable := startvalue to endvalue do statement;

or

for counter_variable := startvalue to endvalue do
            begin
    statement1;
    statement2;
    ……;
end;

Note that there is no semi-colon after the do otherwise the statements will never be executed more than once.

Now try the first example:.......









Download Programming in PASCAL : Iteration / PDF








Programming in PASCAL : Iteration / PDF



0 commentaires: