Chapter 13 - Control Flow

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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.
Background image of page 7

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

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

Page1 / 18

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

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

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