^^Learnings of the Week
Submitted to:
Joyce Niko D. Perez
IV- RIZAL
Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met. It can be predefined as in the loop, or open ended as in while and do-while.
Types of Iterative Statements
l The For statements
l The While statements
l The Do-While statements
For Statements
l The For statement or for loop is considered as a predefined loop because the number or times it iterates to perform its body is predetermined in the loop’s definition.
l The For loop contains a counter whose values determine the number of times the loop iterates. The iteration stops upon reaching the number of times specified in the loop.
l The general form of the for statement is:
for (initialization; condition; increment)
{
statement_sequence;
}
The for loop continues to execute until the condition is True (1). Once False (0), program execution resumes on the statement following the for loop.
While statement
l The while statement or while loop is an open-ended or event-controlled loop.
l The while loop iterates while the condition is TRUE (1).
l When it becomes FALSE (0), the program control passes to the line after the loop code.
l The general form of the while statement is:
while (condition)
{
statement_sequence;
}
}
l The second type of open-ended or event-controlled loop is the do-while statement or do-while loop.
l The general form of the do-while statement is:
do
{
statement_sequence;
} while (condition);
l Do-While is a variation of the while statement which checks the condition at the bottom / end of the loop.
l This means that a do-while loop “always executes at least once”.
l In the do-while loop, when the condition evaluates to TRUE (1), the loop body will be executed, but when FALSE (0), program control proceeds to the next instruction after the do-while loop.


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home