Question: Introduction: The do - while loop was added to C + + to give us a slightly different way to execute a block of code
Introduction:
The dowhile loop was added to C to give us a slightly different way to execute a block of code repeatedly. As you may recall the syntax of the while loop is given by:
initialization statement
while logical expression
block of code to be repeated
update variables in logical expression
The dowhile loop moves the logical expression after the block of code to be repeated. The dowhile syntax is shown below:
initialization statement
do
block of code to be repeated
update variables in logical expression
while logical expression ;
With a dowhile loop, the block of code is executed before the logical expression is evaluated. If the logical expression is TRUE, the block of code is executed again, and the process repeats until the expression is FALSE. With a dowhile it is possible to execute he block of code once even if the logical expression is false. As we will see, this program logic is useful for checking user input.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
