Lecture24 - ComputerProgrammingITAC162. Next Step Control...

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

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 03/03/06 Next Step… Control Structure Conditional If statement Switch statement Conditional operator statement goto Iteration for while do-while Examples Today’s Menu
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Computer Programming I TA C162 . 03/03/06 Switch switch (expression) { case const1: block-1; break; case const2: block-2; break; default: block-3; } next_statement evaluate expression = const1? = const2? block-1 block-2 block-3 T T F F
Background image of page 2
3 Computer Programming I TA C162 . 03/03/06 Switch Example /* same as month example for if-else */ switch (month) { case 4: case 6: case 9: case 11: printf(“Month has 30 days.\n”);break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: printf(“Month has 31 days.\n”);break; case 2: printf(“Month has 28 or 29 days.\n”);break; default: printf(“Don’t know that month.\n”); }
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Computer Programming I TA C162 . 03/03/06 More About Switch Case expressions must be constant. case i: /* illegal if i is a variable */ If no break, then next case is also executed. switch (a) {
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

Lecture24 - ComputerProgrammingITAC162. Next Step Control...

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

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