Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views22 pages

M Iterative Statements

N/A
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)
15 views22 pages

M Iterative Statements

N/A
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/ 22

ITERATIVE

STATEMENTS
LEARNING OBJECTIVES
• Identify the different types of iterative statements.
• Familiarize the basic syntax used in creating iterative
statements.
• Create simple C++ programs using iterative statements.
• Encourage patience, accuracy and honesty in creating simple
C++ programs.
ITERATIVE STATEMENTS
The statements that cause a set of
statements to be executed repeatedly
either for a specific number of times or
until some condition is satisfied.
ITERATIVE STATEMENTS
• Iteration is the process where a set of
instructions or statements is executed
repeatedly for a specified number of time
or until a condition is met. These
statements also alter the control flow of
the program and thus can also be
classified as control statements.
• Iterative statements are most commonly
known as LOOPS.
PARTS OF LOOP
❖INITIALIZATION
❖assigns an initial value to
the loop variable
❖CONDITION
❖a Boolean expression
❖MODIFICATION
❖generally changes the loop
variable
TYPES OF LOOP
• FOR LOOP
• WHILE LOOP
• DO-WHILE LOOP
FOR LOOP
• A deterministic loop in nature, that is, the
number of times the body of the loop is executed
is known in advance.
Syntax
for(initialize; condition; update
(increment/decrement)
{
//body of the for loop
}
FOR LOOP
FOR LOOP
FOR LOOP

https://onlinegdb.com/XS
BVR8R4R
WHILE LOOP
• Used to perform looping operations in situations
where the number of iterations is not known in
advance.
• Continues its execution if the condition is true but
will stop if the condition is false

Syntax
while(condition)
{
/ / body of while loop
}
WHILE LOOP
• Do not specify any explicit initialize and update
expressions
• Control variable must be declared and initialized
before the while loop and needs to be updated within
the body of the while loop
• Executes as long as condition evaluates to True. If
condition evaluates to False in the first iteration, then
the body of while loop never executes.
• Can have more than one expression in its condition.
However, such multiple expressions must be
separated by commas and are executed in the order
of their appearance.
WHILE LOOP

If the while loop condition is never


FALSE then the loop becomes an
infinite loop.
WHILE LOOP
WHILE LOOP
https://onlinegdb.com/0S
TyzvFm5
DO-WHILE LOOP
• Used if the body of the loop is to be executed at least
once, no matter whether the initial state of the condition
is True or False.
• This loop places the condition to be evaluated at the
end of the loop.
• The do...while loop is a variant of the while loop with
one important difference: the body of do...while loop is
executed once before the condition is checked.`
Syntax
Do
{
//body of do while loop
}while(condition);
DO-WHILE LOOP
DO-WHILE
LOOP
https://onlinegdb.
com/2s1P-RurP
DO-WHILE LOOP

https://onlinegdb.c
om/wJmuXt_HO
FOR WHILE DO-WHILE

LOOPS • Used when the number of


iterations is known
• A while loop evaluates the
condition
• The body of the loop is
executed at first. Then the
• If the condition evaluates to condition is evaluated.
true, the code inside the • If the condition evaluates to
while loop is executed. true, the body of the loop
• The condition is evaluated inside the do statement is
again. executed again.
• This process continues until • The condition is evaluated
the condition is false. once again.
• When the condition • If the condition evaluates to
evaluates to false, the loop true, the body of the loop
terminates. inside the do statement is
executed again.
• This process continues until
the condition evaluates to
false. Then the loop stops.
Syntax Syntax Syntax
for(initialize; condition; update) while(condition) Do
{ { {
//body of the for loop / / body of while loop //body of do while loop
} } }while(condition);
LOOPS • Nested Loops
• Loop within the loop; at least 256 levels
• Jump Statements
• goto statement
• making a jump to another point in the program
• https://onlinegdb.com/gnmbKiHjf
• break statement
• provides immediate exit from the loop
• https://onlinegdb.com/RaB0OaDn3
• continue statement
• skips the rest of the loop
REFERENCES
• Textbook
• Beginner’s Guide to
C++ Programming. Pomperada, Jake. Mindshapers Inc.
2019. pp.95-126
• Online References:​
• http://ecomputernotes.com/cpp/control-structures/iteration-
statements
• https://www.mycplus.com/tutorials/cplusplus-programming-
tutorials/introduction-cplusplus-lecture-notes/​
• https://www.w3schools.in/cplusplus-tutorial/constants/​

You might also like