Learnings of the Week - October 18, 2008
ITERATIVE STATEMENTS
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.
The For Statements
- is considered as a predefined loop because the number or times it iterates to perform its body is predetermined in the loop’s definition
- 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
- for is a reserve word in C
- initialization is an assignment statement that is used to set the loop’s counter
- condition is a relational Boolean expression that determines when the loop will exit
- increment defines how the loop’s counter will change each time the loop is separated
- statement sequence may either be a single C statement or a block of C statements that make up the loop body
- 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
The While Statement
- is an open-ended or event-controlled loop
- the while loop iterates while the condition is TRUE (1)
- when it becomes FALSE (0), the program control passes to the line after the loop code
- while is a reserved word in C
- condition is a relational expression that determines when the loop will exit
- Statement_sequence may either be a single C statement or a block of C statements that make up the loop body
The Do-While Statement
- the second type of open-ended or event-controlled loop
- while and do are reserved words in C
- condition is a relational expression that determines when the loop will exit
- Statement_sequence may either be a single C statement or a block C statements that make up the loop body
- Is a variation of the while statement which checks the condition at the bottom / end of the loop
- This means that “always executes at least once”
- 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
Posted by:
RAE ANGELINE S. PALEN


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