Professional Documents
Culture Documents
Statement
A statement gives instructions to the computer that you want to carry out. A simple statement is a single
instruction while a compound statement comprises two or more statements that are enclosed by the
keywords ‘begin’ and ‘end’. A compound statement is useful if you want to perform some instructions in
sequence or repetitively before moving on to the nest set of statements.
Output Statement: Show the Write; Writeln; The cursor remains at the same place
output to the monitor screen Write(Mark); on the screen. The cursor goes to the
Writeln(Mark); start of the next line. Outputs 30.
Write('Score of',Mark); Outputs 30.
Writeln('Score of',Mark); | (|is the cursor)
Outputs score of 30|
Outputs score of 30
| (|is the cursor)
https://www.tutorialspoint.com
Loops
There may be a situation when you need to execute a block of code several number of times. In
general statements are executed sequentially: The first statement in a function is executed first,
followed by the second, and so on. Programming languages provide various control structures
that allow for more complicated execution paths. A loop statement allows us to execute a
statement or group of statements multiple times and following is the general from of a loop
statement in most of the programming languages:
Pascal programming language provides the following types of loop constructs to handle looping
requirements. Click the following links to check their detail.
https://www.tutorialspoint.com
any another while, for or repeat
until loop.
While-do loop
A while-do loop statement in Pascal allows repetitive computations till some test condition is
satisfied. In other words it repeatedly executes a target statement as long as a given condition
is true.
Syntax:
The syntax of a while-do loop is: while (condition) do S;
Where condition is a Boolean or relational expression whose value would be true or false and S
is a simple statement or group of statements within BEGIN ... END block.
For example,
while number>0 do
begin
sum := sum + number;
number := number - 2;
end;
When the condition becomes false, program control passes to the line immediately following
the loop.
Here key point of the while loop is that the loop might not ever run. When the condition is
tested and the result is false, the loop body will be skipped and the first statement after the
while loop will be executed.
https://www.tutorialspoint.com
Example:
program whileLoop;
var
a: integer;
begin
a := 10;
while a < 20 do
begin
writeln('value of a: ', a);
a := a + 1;
end;
end.
When the above code is compiled and executed, it produces following result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
Using the code provided in Lesson 3 handout, add a writeln statement below the loop to display the
value of the variable “a” saying “Your loop has ended because “a” has reached:”
5 Marks
https://www.tutorialspoint.com