UNDERSTANDING
Programming Fundamentals (CS-106) LOOPS
What are loops? 2
Loops are a sequence of program instructions whose
execution is repeated continuously until a condition is met.
Loops 3
Typically, a variable is used to compare for certain
condition whose value is incremented or changed for
every execution.
When a certain condition of that variable is met, then this
repetition is stopped.
Loops - Program Flow 4
Block 1
Block 2
Block 3
Loops - Program Flow 5
Block 1 Block 1
January 1
January 2 January X
January 31
Block 3 Block 3
Types of Loops 6
3 Types of Loops:
For Loop
While Loop
Do While Loop
For Loop - Syntax
Syntax:
for variable = value_1 to value_n
Sequence of statements
next
For Loop - Example
define day as integer
day = 1
for day = 1 to 31 Note: The day value
print “January “+day is incremented by 1
automatically
next
While Loop - Syntax
Syntax:
While condition
Sequence of statements
endwhile
While Loop - Example
define day as integer
day = 1
while day < 32
Note: The day value
print “January “+day is incremented by 1
day = day + 1 manually
endwhile
Do While Loop - Syntax
Syntax:
do
Sequence of statements
while condition
Do While Loop - Example
define day as integer
day = 1
do
Note: The day value
print “January “+day is incremented by 1
day = day + 1 manually
while day < 32
References 13
Fundamentals of Programming Languages #5 |
Understanding Loops – YouTube
(CodeWithPraveen)
Lecture 11: Loops in C++| While Loop in Urdu/Hindi |
Programming Fundamentals C++ | The Kacs (KACS
Learning)
Lecture 11( part-2) : For loop in C++ in Urdu |
Programing Fundamentals in C++ | Kacs – YouTube
(KACS Learning)
Lecture 11:(part 3) Do While Loop IN C++ Urdu |
Loops In C++ | Programing Fundamentals in C++ |
Kacs – YouTube (KACS Learning)
Assignment #5 14
In Dev C++ create separate programs that use
for, while and do-while loops to repeat parts of
the program according to your logic:
1. Draw Flowchart of your programs
2. Share code of your programs
3. Share output of your programs
Email: [email protected] with Subject: Name/Reg - PF Assignment #5