Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

C Language Programming

Lesson 5:
Flow Control
(Part2)

Prepared by:
Prof. Marienel N. Velasco

Unit
Pg. 1
I’m going to talk about

for loop

while loop

do…while loop

Unit
Pg. 2
Loop

• Repetition of action is one reason we rely on computers.


• When there are large amount of data, it is very convenient to
have a control mechanism that repeatedly execute specific
statements.
• In programming, a loop is used to repeat a block of code
until the specified condition is met.
• C programming has three types of loops:
for loop
while loop
do...while loop

Unit
Pg. 3
C for loop

Syntax:

Unit
Pg. 4
C for loop

How it works:

Unit
Pg. 5
C for loop

Example #1:

Unit
Pg. 6
C for loop

Output#1:

Unit
Pg. 7
C while loop

Syntax:

Unit
Pg. 8
C while loop

How it works:

Unit
Pg. 9
C for loop

Example #2:

Unit
Pg. 10
C for loop

Output#2:

Unit
Pg. 11
C do…while loop

Syntax:

Unit
Pg. 12
C do…while loop

How it works:

Unit
Pg. 13
C do…while loop

Example#3:

Unit
Pg. 14
C do…while loop

Output#3:

Unit
Pg. 15
Hands-on Exercises

Hands-on
Activity #1:

Program to
calculate the
sum of first n
natural
numbers

Unit
Pg. 16
Hands-on Exercises

Hands-on
Activity #2:

Program to
print half
pyramid using
*

Unit
Pg.17
Hands-on Exercises

Hands-on
Activity #3:

Program to
print half
pyramid using
numbers

Unit
Pg.18
Hands-on Exercises

Hands-on
Activity #4:

Program to
print half
pyramid using
alphabets

Unit
Pg.19
That’s all folks!

Thank you for listening!

Unit
Pg. 20

You might also like