Loop/Cycle

Parts
Initialization
Start of loop. Examples: i=0, i = a.begin().
Condition
Stay or exit That is the question. Examples: i < n, i != a.end()
Body
Main part of loop/cycle. Examples: cout << i << '\n';
Incrementation
Procede to next step. Example: i++, i--, i+=k, i-=k
Forms
Classic
"General" form Language specific Example Output
initialization();
loop_again:
 if( false == condition ) 
  goto loop_exit;
   body();
   incrementation();
  goto loop_again;

loop_exit:;
  
initialization();
while( true == condition() )
 {
  body();
  incrementation();
 }
i=0;
while( i < 10 )
 {
  cout << i << '\n';
  i++;
 }
0
1
2
3
4
5
6
7
8
9
One obligated pass
"General" form Language specific Example Output
initialization();
loop_again:
 body();
 incrementation();
if( true == condition() ) 
 goto loop_again;
initialization();
do
 {
  body();
  incrementation();
 }while( true == condition() );
i=0;
do
 {
  cout<< i << '\n';
  i++;
 }while( i < 10 ); 
0
1
2
3
4
5
6
7
8
9
Save the last incrementation
"General"form Example OutPut
initialization();
loop_again:
 body();
 if( false == condition )
  goto loop_exit;
   incrementation();
  goto loop_again;
 loop_exit:;
  
i=0;
loop_again:
 cout << i << '\n';
 if( i < 10 )
  {
   i++;
   goto loop_again;
  }
0
1
2
3
4
5
6
7
8
9
10