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

Do While Loop

The do-while loop is an iterative control structure that executes one or more statements at least once, even if the given condition is false. The condition is checked after executing the body of the loop. This means the statements inside the loop body are guaranteed to run at least once before evaluating if the condition is true or false. The syntax of a do-while loop includes the do keyword followed by a statement block, and the while keyword along with a condition to be checked at the end of each iteration.

Uploaded by

Umair Ashfaq
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Do While Loop

The do-while loop is an iterative control structure that executes one or more statements at least once, even if the given condition is false. The condition is checked after executing the body of the loop. This means the statements inside the loop body are guaranteed to run at least once before evaluating if the condition is true or false. The syntax of a do-while loop includes the do keyword followed by a statement block, and the while keyword along with a condition to be checked at the end of each iteration.

Uploaded by

Umair Ashfaq
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

B Y C O M P U T ER L A N GU A GE

PRESEN TA T I O N
Do-while loop:
The do-while loop is an iterative control in C++
The loop is executes one or more statements while the given
condition is true. The condition in this loop checked after the
body of loop.
The do while loop checks the condition at the end of the loop.
This means that the statements inside the loop body will be executed at
least once even if the condition is never true.
FLOWCHART
Syntax:
The syntax of do while loop is as follows Loop body
do {
  true
 // code block to be executed
Condition
}
while (condition);
False
do while loop:
Do:
It is the keyword that indicate the beginning of the loop.
Condition:
The condition is given as a relational expression. The loop continues
only the given condition is true. If the condition is true . If the condition is
false ,the loop is terminated
Statement :
Statement is the instruction that is executed when condition
is true .two more statement are written in braces{}.it is called the
body of the loop.
Working of do-while loop:
• The body of the loop is executed at first. Then the condition is
evaluated.
• If the condition evaluates to true, the body of the loop inside the 
do statement is executed again.
• The condition is evaluated once again.
• If the condition evaluates to true, the body of the loop inside
the do statement is executed again.
• This process continues until the condition evaluates to false. Then the
loop stops.
Do while loop Program Output:
12345

#include <iostream>
using namespace std;
int main()
{
int i = 1;
// do...while loop from 1 to 5
do { cout << i << " "; ++i; }
while (i <= 5);
}
include <iostream>
output
using namespace std;
Enter a number: 6
int main() Enter a number: 12
{ Enter a number: 7
Int number = 0; Enter a number: 0
Enter a number: -2
int sum = 0; The sum is 25
do { sum += number; cout << "Enter a number: "; cin >> number; }
while (number >= 0);
cout << "\nThe sum is " << sum << endl;
}

You might also like