Algoritma & Pemrograman: Control Flow
Algoritma & Pemrograman: Control Flow
Prepared by
Frans Panduwinata, S.Kom, M.T
Loops
• EXAMPLE:
int count;
for( count = 1; count <= 10; ++count)
cout << count<< ". loop" << endl;
• EXAMPLE:
for( int i = 0; i < 10; cout << i++ )
;
• EXAMPLE:
int x, i, limit;
for( i=0, limit=8; i < limit; i += 2)
x = i * i, cout << setw(10) << x;
• EXAMPLE:
x = (a = 3, b = 5, a * b);
Screen Output:
Structogram for do-while
The do-while Statement
Screen Output:
Structogram for the if-else Statement
Selections with if-else
– The return value of the function, func(), is used to initialize the variable x.
– If this value is not 0, the statements in the next block are executed.
– The variable x no longer exists after leaving the if statement.
Sample Program
Structogram for an else-if Chain
Layout and Program Flow
Screen Output:
Screen Output:
EXERCISES