Pascal - Exercise Example
Pascal - Exercise Example
Strength
General Certificate of Education (Ordinary Level) Examination (O/L) kj ks¾foaYh / New Syllabus
Pascal program – Grade 11 Priyanthi Fernando 80 S I,II
begin
begin a := 10;
a := 10; (* repeat until loop execution *)
while a < 20 do repeat
begin writeln('value of a: ', a);
writeln('value of a: ', a); a := a + 1
a := a + 1; until a = 20;
end.
end;
readln; Result
end. value of a: 10
value of a: 11
Example: 2 FOR DO Loop value of a: 12
value of a: 13
The syntax for the for-do loop in Pascal is as value of a: 14
value of a: 15
follows – value of a: 16
value of a: 17
for < variable-name > := < initial_value > to value of a: 18
value of a: 19
[down to] < final_value > do S;
begin
program forDOLoop;
var a := 10;
a: integer; (* repeat until loop execution *)
repeat
begin writeln('value of a: ', a);
for a := 10 to 20 do a := a + 1
until a > 20;
begin
readln;
writeln('value of a: ', a);
end; end.
readln;
end.
Result
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
value of a: 20
Example 5. Example 7: Hello program
Example 8:
program whileLoop;
var
count:integer;
begin
Example 6.
for count := 0 to 5 do
program whileLoop; write('Hello, ');
var readln;
x: integer; end.
count:integer;
begin
for x := 0 to 2 do
write('#');
For x := 1 to 3 do
writeln('#');
readln;
end.
Example 9.
program whileLoop;
var
revision count:integer;
begin
for count := 0 to 5 do
write('Hello ');
readln;
end. *
program whileLoop; *
var
x: integer; *
count:integer; *
begin
for x := 0 to 2 do
*
write('#');
For x := 1 to 3 do
writeln('#');
readln;
end.
program forDOLoop;
var
i: integer;
begin
for i := 1 to 5 do
begin
writeln('*');
end;
readln;
end.
Answer