




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























if ( expression ) true_statement ; else else_ statement ;
or
if ( expression ) { true_statement 1; true_statement 2; ……} else { else_ statement 1; else_ statement 2; ……}
If the expression evaluates to TRUE, then the true_statement (s ) is(are) executed. If the expression evaluates to FALSE then the else _ statement(s) is(are) executed.
if ( expression1 ) true_statement 1; else if ( expression2 ) true_statement 2; else if ( expression3 ) true_statement 3; else else_ statement ;
If expression1 evaluates to TRUE, then the true_statement1 (s ) is(are) executed. If expression evaluates to FALSE then the next expression ( expression2 ) is evaluated. If expression evaluates to TRUE, then the true_statement2 (s ) is(are) executed. If none of the expressions evaluate to TRUE then the else_statement (s ) is(are) executed.
int x, y, z; x = 10; y = 50; z = 5;
if ( x == y ) z = x/2; else if ( x > y ) z = x * 2 ; else z = x;
int x, y, z; x = 10; y = 50; z = 5;
if ( x == y ) z = x/2; else if ( x > y ) z = x * 2 ; else z = x;
int x, y, z; x = 10; y = 50; z = 5;
if ( x == y ) z = x/2; else if ( x > y ) z = x * 2 ; else z = x;
int x, y; x = 10; y = 20;
if ( x = y ) printf (“Blah, blah, blah”) ; : :
while ( expression ) statement ;
or
while ( expression ) { statement 1; statement 2; statement 3; etc. }
When program execution enters the while loop, the expression is evaluated. If the expression evaluates to TRUE the statement (s) is(are) executed. When all statements are executed, the program will be to this process again (evaluate the, expression, …… etc). If the expression evaluates to FALSE the statement (s) is(are) skipped and execution continues at the statement(s) immediately following the while loop structure.
while ( 1 ) printf (“Blah, blah, blah”) ; : :
do statement ; while ( expression ) ;
or
do { statement 1; statement 2; statement 3; etc. } while ( expression ) ;
The do/while loop is very similar to the while loop except that the expression is evaluated at the end of the loop. When program execution enters the do/while loop, the statement (s) is(are) executed. If the expression evaluates to TRUE the program continues at the beginning of the do/while loop. This process continues as long as the expression evaluate to TRUE. The important difference between while and do/while is that the do/while statement (s) is(are) ALWAYS executed at least once.
do printf (“Blah, blah, blah”) ; while (0);
int y = 15; for (int x = 1; x = = 10; x++) --y;
int y = 15; for (int x = 1; x = = 10; x++) --y;