Start learning today, and be successful in your academic & professional career. Start Today!

• ## Related Services

### Branching

• Branching allows program to process different code blocks depending on testable situations
• Variables have a “scope” that is limited to the code block
• The ‘if” statement processes a code block if its expression is true
• The “else” clause processes a code block if the expression for its corresponding “if” statement is false
• The ‘if” statement and/or its “else” clause may have more “if” statements nested in its code block
• A special case of “else” nesting is the “chained if”, where a number of cases may be tested until one evaluates to true
• A “switch” statement works like a “chained if” for an integer expression– the case that matches the integer value is processed
• A “conditional” statement uses the “ternary operator” to provide a value conditional on its expression – the first value if true, or the second value if false
• A “goto” statement unconditionally branches to another location in the code, but is known to lead to poor quality software
• Here is a link that includes a discussion of various kinds of branching statements: http://www.cplusplus.com/doc/tutorial/control/

### Branching

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

• Intro 0:00
• Overview 0:03
• Code Blocks, Scope 1:32
• 'Scope' of the Block of Code
• Scope Example 2:56
• 'If' Statement 5:20
• 'Else' Clause 6:43
• Example
• Nested 'If' 7:52
• Example
• More Nested 'If' 8:41
• 'If' Without Blocks 9:53
• 'Chained If' 10:35
• Example
• 'If' Statement's Expression 11:36
• 'If' Statement Stylistic Notes 12:55
• 'Else' Clause Stylistic Notes 14:24
• 'Switch' Multiple Choice 15:15
• 'Switch' Like 'Chained-If' 16:35
• 'Switch Tricks' 17:56
• Leave Break Out
• 'Conditional' Statement Cautions 19:54
• 'Conditional' Statement Example 21:56
• Another Example
• 'Goto' and 'Label' 23:40
• Do's and Don'ts 1:54