Chapter 13 - Control Flow

Chapter 13 - Control Flow - "Don't worry if it doesn't work...

This preview shows pages 1–8. Sign up to view the full content.

Chapter 13 Control Structures in C “Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering

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

View Full Document
BYU CS/ECEn Variables and Operators 2 Topics to Cover… n Control Structures n if-else Statement n switch Statement n while Statement n do-while Statement n for Statement n Loops n Break and Continue n GOTOs and Labels n Optimizing Compilers
BYU CS/ECEn Variables and Operators 3 Terms… n sentinel n control structures n systematic decomposition n iterator n nesting n constant folding n sub-expression n interprocedural n inlining n peephole optimization

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

View Full Document
BYU CS/ECEn Variables and Operators 4 Control Structures n We looked at three constructs for systematic decomposition: Test Task 1 Task 2 True False § The conditional construct Test Task 1 True False § The iteration construct Part I Part II § The sequential construct n C has many conditional and iteration constructs: n if, if-else n switch n for n while, do-while Control Structures
BYU CS/ECEn Variables and Operators 5 The if-else Statement n Perform if-action if a condition is true. Otherwise, perform else-action. n Form: if ( expression ) statement1 else statement2 § Example: if (x) { y++; z++; } else x==0 ? y++; z++; y--; z--; True False if-else Statement

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

View Full Document
BYU CS/ECEn Variables and Operators 6 The if-else statement n You can connect conditional constructs to form longer sequences of conditional tests: if ( expression1 ) statement1 else if ( expression2 ) statement2 else if ( expression3 ) statement3 else statement4 n An else is associated with the closest unassociated if . if-else Statement if ( expression1 ) { if ( expression2 ) statement2 else statement3 } if ( expression1 ) { if ( expression2 ) statement2 } else statement3
BYU CS/ECEn Variables and Operators 7 The switch Statement n Performs actions based on a series of tests of the same variable. n Form: switch ( expression ) { case const-expr : statements case const-expr : statements case const-expr : statements default: statements } n The break statement causes an immediate exit from the switch.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 18

Chapter 13 - Control Flow - "Don't worry if it doesn't work...

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

View Full Document
Ask a homework question - tutors are online