Sunday, January 18, 2009

ITERATIVE STATEMENTS.*
by: mary trishia v. tabigue
Iterative statements repeated execution of list of statements, depending on the value of a boolean expression.
Syntax:
while ( ) {
}
As long as the boolean expression is true, the statement list is executed repeatedly.
When the boolean expression is false, the statement list is skipped, and execution continues with the statement following the while statement.
Style: The statement list should be indented.
example:
#include
using namespace std;
int main () {
int Entry;
int Counter;
cout << "Enter a positive integer: ";
cin >> Entry;
Counter = 1;
while (Counter <= Entry) {
cout << "Iteration " <<>
Counter = Counter + 1;
}
return 0;
}
Program output:
>iterative
Enter a positive integer: 4
Iteration 1 of 4
Iteration 2 of 4
Iteration 3 of 4
Iteration 4 of 4

No comments: