Course S2-04 - Pascal - Printing Patterns
Course S2-04 - Pascal - Printing Patterns
2024-2025
1
A. GHALI
Computer Science 2024/2025
Patterns
A pattern is an original object used to make copies, or a set of repeating objects in a decorative
design and in other disciplines. The reason of this course is to write an algorithm and a step-by-
step procedure for solving a problem of printing the patterns. In the context of this examples, is
a set of well-defined instructions for performing a specific task to solving a problem.
Understanding algorithms is essential for anyone interested in mastering solving problem.
This chapter is intended to learn a useful statements (break and continue) but not necessary,
that can help you to printing the next examples of patterns and numbers.
When the break statement is encountered inside a loop, the loop is immediately
terminated and program control resumes at the next statement following the loop.
It can be used to terminate a case in the case statement (covered in the next chapter).
If you are using nested loops (i.e., one loop inside another loop), the break statement will stop
the execution of the innermost loop and start executing the next line of code after the block.
Flow Diagram
2
A. GHALI
Computer Science 2024/2025
Example
program exampleBreak;
var
a: integer;
begin
a := 10;
while a < 20 do
begin
writeln('value of a: ', a);
a:=a +1;
if( a > 15) then
break;
end;
end.
When the above code is compiled and executed, it produces the 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
The continue statement in Pascal works somewhat like the break statement. Instead of forcing
termination, however, continue forces the next iteration of the loop to take place, skipping any
code in between.
For the for-do loop, continue statement causes the conditional test and increment portions of
the loop to execute. For the while-do and repeat...until loops, continue statement causes the
program control to pass to the conditional tests.
3
A. GHALI
Computer Science 2024/2025
Flow Diagram
Example
program exampleContinue;
var
a: integer;
begin
a := 10;
repeat
if( a = 15) then
begin
a := a + 1;
continue;
end;
writeln('value of a: ', a);
a := a+1;
until ( a = 20 );
end.
When the above code is compiled and executed, it produces the 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: 16
value of a: 17
value of a: 18
value of a: 19
4
A. GHALI
Computer Science 2024/2025
Example 1:
Example 2:
Example 3:
Example 4:
5
A. GHALI
Computer Science 2024/2025
Example 5:
Example 6:
Example 7:
Example 8:
6
A. GHALI
Computer Science 2024/2025
Example 9:
Example 10:
1
12
123
1234
12345
12345
1234
123
12
1
7
A. GHALI
Computer Science 2024/2025
1
232
34543
4567654
567898765
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1
23
456
7 8 9 10
8
A. GHALI