Using Loop
constructs
Loop construct are
used to execute one or more lines of code repetitively.
The While loop
The do..while loop
The for loop
While Loop
The while loop
construct is used to execute a block of statement for a definite number of
times depending on a condition.
Syntax of
the while loop construct
While(expression)
{
Statement;
}
Do..while
Loop
In the do while loop
the body of loop executed at least once and the condition is evaluate for the
subsequent iteration.
Syntax of
the do..while loop
Do
{
Statement;
}
While(expression);
The for
loop
The for loop
structure is used to execute a block of statement for a specific number of
times.
Syntax for
the for Loop
For(initialization;
termination; increment/decrement)
{
Statements
}
The Break
and continue statement
As with a while loop,
you can use the break statement to exit for loop. The continue statement is
used to skip all the subsequent instruction and take control back to the loop.
- · The break and continue statement are used to control the program flow within the loop.
No comments:
Post a Comment