1.Understand the purposeof a
Do/While Loop
how it
that
a
Learn
ensures
block of
executes at
once
checking
code
least
before
the
condition.
HOME ABOUT MORE
OBJECTIVES:
2.Differentiate Do/While Loop
from other loops
Recognize how it
differs from While
and For loops in
terms of execution
flow.
3.Perfect the 5-question quiz
Test
comprehension of
the Do/While Loop
concept, syntax,
and functionality
with a short quiz.
5.
WHAT IS A
DO/WHILE
LOOP?
-ADo/While Loop is a type of loop in C++ that ensures the
code inside the loop executes at least once before checking
the condition. Unlike a while loop, which evaluates the
condition first, a do/while loop runs the code block first and
then evaluates the condition. This makes it useful in
scenarios where you need to execute a set of instructions at
least once, such as user input validation, menu-driven
programs, or repeated processes that must occur before
checking a condition.
HOME ABOUT MORE
6.
Ensures Execution atLeast Once
Unlike other loops, a Do/While Loop
guarantees that the code inside runs at
least one time, even if the condition is
false.
HOME ABOUT MORE
PURPOSES OF A DO/WHILE
LOOP
01 0 2
User Input Validation
It is commonly used in programs that
require user input, ensuring the user
enters valid data before proceeding.
7.
PURPOSES OF ADO/WHILE
LOOP
0 3
Menu-Driven Programs
Frequently used in programs with
menus, allowing users to interact with
options before deciding to exit.
0 4
Repetitive Processes with Post-
Condition Checking
Useful in scenarios where an action
must be performed first, and then the
condition is checked for repetition, such
as game loops or repeated calculations.
HOME ABOUT MORE
8.
STRUCTURE OF
A DO/WHILE
LOOP
ABOUTMORE
do {
/ / code block to be executed
} while (condition);
HOME
EXPLANATION:
1.do { } Block – The code inside this block
executes at least once, no matter what the
condition is.
2.while (condition); – After executing the
block, the condition is checked.
If true, the loop repeats.
If false, the loop stops.
9.
EXAMPLES: PRINTING 1TO
5
HOME ABOUT MORE
#include <iostream>
using namespace std;
int main()
{
int i = 1;
do {
cout << i << "n";
i++;
} while (i <= 5);
return
0;
}
OUTPUT:
1
2
3
4
5
10.
Your time toshine!
(Hands on activity)
Create a program that acts
like a magic number
guessing game from
numbers 1-10 using
do/while loop.
Correct answer is your
choice
Welcome to the Magic Number
Guessing Game!
I have chosen a number between
1 and 10. Can you guess it?
Enter your guess: (placeholder)
Try again!
Enter your guess: (placeholder)
Congratulations! You guessed the
magic number!