0% found this document useful (0 votes)
23 views1 page

Break Goto Return Continue: While Do

A while loop executes zero or more times based on a test condition, with the condition checked at the start of each iteration. A do-while loop always executes its body at least once, as the test condition is checked at the end of each iteration. Both loops allow terminating the current iteration early using continue or exiting the loop completely using break or return.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

Break Goto Return Continue: While Do

A while loop executes zero or more times based on a test condition, with the condition checked at the start of each iteration. A do-while loop always executes its body at least once, as the test condition is checked at the end of each iteration. Both loops allow terminating the current iteration early using continue or exiting the loop completely using break or return.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

) The test of expression takes place before each execution of the


loop; therefore, a while loop executes zero or more
times. expression must be of an integral type, a pointer type, or a
class type with an unambiguous conversion to an integral or pointer
type.

each of the statements within the block. The body of the loop (the
block of code) is enclosed in braces and indented for readability.
(The braces are not required if only ONE statement is used in the
body of the loop.)

A while loop can also terminate when a break, goto, or return within
the statement body is executed. Use continue to terminate the current
iteration without exiting the whileloop. continue passes control to
the next iteration of the while loop.

The do-while loop is an exit-condition loop. This means that the


body of the loop is always executed first. Then, the test condition is
evaluated. If the test condition is TRUE, the program executes the
body of the loop again. If the test condition is FALSE, the loop
terminates and program execution continues with the statement
following the while.

2.) Syntax:

4.) Syntax:

The syntax of a while loop in C++ is:

The syntax of a do...while loop in C++ is:

while(condition)

do

{
statement(s);

statement(s);

}while( condition );

3.) The do-while loop is similar to the while loop, except that the test
condition occurs at the end of the loop. Having the test condition at
the end, guarantees that the body of the loop always executes at least
one time. The format of the do-while loop is shown in the box at the
right.

Notice that the conditional expression appears at the end of the loop,
so the statement(s) in the loop execute once before the condition is
tested.

The test condition must be enclosed in parentheses


andFOLLOWED BY A SEMI-COLON. Semi-colons also follow

You might also like