Cari Blog Ini

20 November 2010

IT - Iteration Statements

Iteration Statements

* Control Structure that controlling how many statements/block is executed.
* As a part of programming fundamental.
* Coding Efficiency.
* Three types of Iterations
1. while
2. do – while
3. for

* Iteration can be implemented inside iteration (nested)



1. WHILE statements





* Loop-continuation-condition
 - As boolean expression.
  - Loop is executed when its condition is true.
 - Its argument is inside parentheses (…)
* Don’t put a semi-colon after while(…)
* Curly block is needed when it has more than one statement.

2. DO-WHILE Statements







* Loop-continuation-condition
 - As boolean expression
 - Loop is executed when its condition is true.
 - Its argument is inside parentheses (…)
* Starts by do and ends by while(…) and Semicolon(;)
* Curly block {…} is needed when it has more than one stetement.

3. FOR statements












 * Initial-action
 - Variable is initialized
* Loop-continuation-condition
 - As boolean expression
 - True means loop is executed.
 - Its locations between initial-action and action-after-each-iteration divides by semicolon(;)
* Action-after-each-iteration
 - Execute after looping
 - Usually in increment or decrement form.
 - Control Variable.

* Starts with for(…;…;…) and ends without semicolon(;) except in special condition.
* Curly block is needed when it has more than one statement.