Академический Документы
Профессиональный Документы
Культура Документы
will be useful to refresh your knowledge in a hands-on approach, guarantee performance and
permit easier maintenance of the used code and test derivations of the examples used.
b. While
while ( expression )
statement
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.
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.
c.While True
There are two statements ( break; and continue; ) built in C++ programming to alter the
normal flow of program.
Loops are used to perform repetitive task until test expression is false but sometimes it
is desirable to skip some statement/s inside loop or terminate the loop immediately with
checking test condition. On these type of scenarios, continue; statement
and break; statement is used respectively. The break; statement is also used to
terminate switch statement.
C++ break Statement
The break; statement terminates the loop(for, while and do..while loop) and switch
statement immediately when it appears.
d. While True
The syntax of a while loop in C++ is:
while(condition)
{
statement(s);
}
Here, statement(s) may be a single statement or a block of statements. The condition may be
any expression, and true is any non-zero value. The loop iterates while the condition is true.
When the condition becomes false, program control passes to the line immediately following the
loop.
e.Do / While
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.
f.Jump/Loop
The FOR loop construct in Ada does not give the programmer the ability to directly modify the loop control
variable during the execution of the loop. Instead, a valid range must always be provided before entering a
loop. Because exact adherence to the task is impossible, we have three versions to approximate a solution.
Looper_1 goes through a range of values which are even. Looper_2 multiples each value by two. Looper_3
most closely adheres to the requirements of this task, and achieves this by using a second range for the
indices.
g.If / else
if ( expression )
statement1
[else
statement2]
If the value of expression is nonzero, statement1 is executed. If the optional else is
present, statement2 is executed if the value of expression is zero. expression must be of
arithmetic or pointer type, or it must be of a class type that defines an unambiguous
conversion to an arithmetic or pointer type. (For information about conversions,
seeStandard Conversions.)