Program Control: Repetition
Repetition is the action of repeating something that has already been processed. The most common repetition in c are: if, if-else, else-if, while, do-while, for, and switch-case-break.
1. If
The syntax of "If" repetition :
if ( condition ) {
statement;
}
2. If-else
The syntax of "If-else" repetition :
if ( condition1 ) {
statement1;
else {
statement2;
}
3. Else-if
The syntax of "Else-if" repetition :
if ( condition1 ) {
statement1;
else if ( condition2 ) {
statement2;
else {
statement3;
}
4. While
The syntax of "While" repetition :
statement;
while ( condition );
5. Do-while
The syntax of "Do-while" repetition :
do {
statement;
} while ( condition );
6. For
The syntax of "For" repetition :
for ( exp1, exp2, exp3 ) {
statement;
}
7. Switch-case-break
The syntax of "Switch-case-break" repetition :
switch ( exp ) {
case exp1 :
statement1;
break;
case exp2 :
statement2;
break;
default:
statement3;
}
No comments:
Post a Comment