notes6

notes6 - Control Statements if statement (same as Java)...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Control Statements if statement (same as Java) if(expr){ .... }else{ //else body } (expr) in the if statement is converted to int. If (expr) != 0, then (expr) is true and the body of the if is executed. Otherwise, if (expr) == 0, the (expr) is false and the body is not executed. If "else" is used then the else body is executed. int i; ... if(i != 0){ ... } equivalent to if(i){ ... } while statement while (expr){ ...//body } execute body while (expr) is true Example while ( i < J ){ ...//body }execute body while i < J for statement "for" statement is typically used in situations when you know in advance the number of iterations for( expr1; expr2; expr3 ){ //body } Example int i;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
for( i = 0; i < 10; i++) { //body } However you can use the for where a while is also used. We can write a for loop as a while in the following way. expr1; while(expr2){ //body expr3; } Expr1 and expr3 are usully "coma expressions" for( i = 0; J = 0; i < 10; j++, J--){ //body } Forever Loops while(1){ //body → runs forever } for( ; ; ){ //body → runs forever } switch statement switch(expr){ case const 1; . . . break; case const 2; . . . break; . . default; . . break;
Background image of page 2
} expr is evaluated and converted to an int if "expr" is equal to any of the const 1, . . const n then it will jump to that section. default : issued if expr did not match any of the constant
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

notes6 - Control Statements if statement (same as Java)...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online