Loop or control statements
looping refers to the ability of a block of code to repeat itself.The repetition can be for a predefined number of times or it can go until certain condition are met.
- while statement
- do while statement
- for statement
While Statement:
The while statement is a basic loop statement used to repeat the execution of a set of statement by specified condition is true.
syntax:
while(condition)
{
statement;
}
Do while statement:
The do while statements is similar to the while statements the only difference is that the looping condition is checked that the end of the loop instant the beginning.These ensure that the enclosed statement are execute at least once.
syntax:
do
{
statement;
}
while (condition);
For loop:
The for statement is similar to the while statement it repeatedly execute a set of statement by a condition is true.It is difference from the while statement that is designed to update a variable of after each loop iteration.
syntax:
for(initialization;condition;update statement)
statement;
{
statement;
}
0 Comments