In most PC programming languages, a do while loop is a control flow statement that executes a number of code at least once, and afterward over and again executes the code, or not, contingent upon a given Boolean condition at the end of the code.

The do while loop construct consists of a procedure, symbol and a condition. To begin with, the code inside the block is executed, and after that, the condition is evaluated. In the event that the condition is true, the code inside the block is executed once more. This repeats until the condition when the condition turns out to be false. Since do while loop checks the condition after the block of code is executed, the control structure is often also called a post-test circle. Stand out from the while loop, which tests the condition before the code inside the block is executed, the do-while loop is an exit condition circle. This implies the code should dependably be executed first and afterward, the expression or test condition is evaluated. In the event that it is valid, the code executes the body of the loop once more. This procedure is repeated as long as the expression assesses to true. On the off chance that the expression is false, the loop ends and control exchanges to the statement following the do-while loop. As such, though a while loop sets reality of an announcement as a conditioning point of reference for the code's execution, a do-while loop accommodates the activity's progressing execution subject to defeasance by the condition's falsity, which falsity (i.e., reality of the condition's negation) is set as a condition subsequent.

It is conceivable, and now and again attractive, for the condition to dependably evaluated to true, making an interminable loop. At the point when such a circle is made deliberately, there is normally another control structure, (for example, a break statement) that permits termination of the loop.

A few languages may utilize an alternate naming tradition for the type of the loop. For instance, the Pascal language has a "repeat until" loop, which keeps on running until the point when the control expression is valid (and after that it terminates) whereas a "while" loop runs while the control expression is valid (and ends once the terminates turns out to be false).
C++ do-while 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 test expression is checked.
Syntax
do
{
//codes
}
While(test expression);


Program
#include <iostream>
#include <conio>


int main () {

   int a = 10;               // variable dicleration

   // do
   do {
      cout << "value of a: " << a << endl;
      a = a + 1;
   }
   while( a < 20 );  //condition
getch ();
   return 0;
}
Output of Do while loop







 
do while loop cpp
do-while loop in cpp

2 Comments

  1. Lease a Car Islamabad Airport has become proficient assets i.e. experienced work, most recent model of vehicles, open business districts, and ace working relations with the accomplices in the development business, for example, surely understood inn frameworks, evident flying transports, and best visit supervisors to get the most connected with rates and lucrative association can anticipate the customers. Islamabad Rent a Car Why you should pay for the extra space that will be un-utilized for if all else fails. Rent an auto clusters set forward best rental auto benefits in Islamabad that join both sensible rates and quality affiliation.

    ReplyDelete

Post a Comment

Previous Post Next Post