0% found this document useful (0 votes)
0 views

Course S2-04 - Pascal - Printing Patterns

The document outlines a course on Computer Science for the academic year 2024/2025 at Kasdi Merbah Ouar gla University, focusing on algorithms and programming in Pascal. It explains the usage of the break and continue statements in Pascal, providing examples and flow diagrams for clarity. Additionally, it includes examples of printing various patterns and numbers, such as pyramids and Pascal's Triangle.

Uploaded by

youcefgh45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Course S2-04 - Pascal - Printing Patterns

The document outlines a course on Computer Science for the academic year 2024/2025 at Kasdi Merbah Ouar gla University, focusing on algorithms and programming in Pascal. It explains the usage of the break and continue statements in Pascal, providing examples and flow diagrams for clarity. Additionally, it includes examples of printing various patterns and numbers, such as pyramids and Pascal's Triangle.

Uploaded by

youcefgh45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Computer Science 2024/2025

MINISTRY OF HIGHER EDUCATION AND SCIENTIFIC RESEARCH

KASDI MERBAH OUARGLA UNIVERSITY

FACULTY OF HYDROCARBONS, RENEWABLE ENERGY, EARTH


AND UNIVERSE SCIENCES --FHERTU—

HYDROCARBON PRODUCTION DEPARTMENT

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.

Pascal - Break Statement

The break statement in Pascal has the following two usages −

 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.

The syntax for a break statement in Pascal is as follows − break;

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

Pascal - Continue Statement

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.

The syntax for a continue statement in Pascal is as follows − continue;

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

Examples to print Pyramids and Patterns Starts (*)

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:

Examples to print Pyramids and Patterns Numbers

Example 1: Half Pyramid of Numbers

1
12
123
1234
12345

Example 2: Inverted half pyramid of numbers

12345
1234
123
12
1

7
A. GHALI
Computer Science 2024/2025

Example 3: Full Pyramid of Numbers

1
232
34543
4567654
567898765

Example 4: Pascal's Triangle

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

Example 5: Floyd's Triangle.

1
23
456
7 8 9 10

8
A. GHALI

You might also like