Program Logic

Learning Unit 6

Decision Structures

Decision Structures

Learning Objectives

In addition to all previous competencies, upon completion of this unit, you should be able to:

Unit Learning Activities

Decision Structures are a fundamental concept in computer programming. They are sometimes called control statements. When you use a decision structure, you control the flow of your application. It is up to you to “decide” what to do based on the desired end results. Using decision structures is like flow-charting your code. If thing “A” happens, then do thing “B”, however, if thing “A” does not happen, then do thing “C”.

Decision structures are instrumental for end-user validation. You have seen this in action in my example code. Also, think about it...if a required field on a form is blank, you do not want to proceed with processing. If “blank” ask end-user to complete the form, else continue processing.

Each link below takes you to a specific chapter within this unit. Please take the time to review all the chapters and when available, complete the interactive activities.

"I think and think for months and years. Ninety-nine times, the conclusion is false. The hundredth time I am right." - Albert Einstein
  1. Single Decision Structure
    • What is “true condition”?
    • Relational Operators
    • Equality ( == )
    • Inequality ( != )
    • Greater Than ( > )
    • Less Than ( < )
    • Greater Than or Equal ( >= )
    • Less Than or Equal ( <= )
    • Decision Structure Syntax
    • Detailed Example
  2. Dual Alternative Decision Structure
    • Boolean Expression
    • Difference Between if and if/else
    • Test Your Knowledge - Interactive activity
    • Detailed Example
  3. Multiple Alternative Decision Structure
    • Testing One Variable for Different Values
    • The Flow of the Code
    • Interactive Live Demo
    • Limit Your else if Statements
    • Detailed Example
  4. Multiple Boolean Expressions
    • The Logical OR ( || ) Operator
    • The Logical AND ( && ) Operator
    • Common Errors
    • Detailed Example
  5. Nested Decision Structures
    • Nested if Statements
    • Nested if/else Statements
    • Interactive Live Demo
  6. The switch Structure
    • The switch Statement
    • Take a break;
    • Things to Remember
    • Detailed Example
  7. This unit includes these full-process examples