Conditional Statements


Click here to start

Table of Contents

Conditional Statements


Logical Data in C

Logical Expressions

Relational Operators

Relational Examples

Combined Expressions

Complex Example

Logical Operators

Logical Expression

AND (&&) and OR (||)

Logical Examples

Short-Circuit Aspect


Complex Expressions


Decision Making

IF Statement

Flow of Execution

Flow Chart for our Problem

Code for Solution

Trace of Solution

Trace of Solution

Executing > 1 Statement in an If

> 1 Stmt in an If

> 1 Stmt in an If (A solution)

Statement in If

Two-Way Selection

Two-Way Selection with If

If-Else Statement

FindMax with If-Else

Using If-Else for Robustness

Compound Statements and If-Else

Programming Tip: Compound Stmt

Programming Tip: Indenting

Programming Tip: Conditions

Multiway Selection

Multiway Flow Chart

Multiway with If-Else

Indenting If-Else Combinations

Conditions Checked in Reverse

Ordering Conditions

Multiway with If Statements

Program Robustness

Completed Code

Nesting Example

Matching Else Example

Matching Single Else

Matching Single Else Solutions

Choosing Conditions

Another Multiway Method

Switch Statement

Switch Format

Switch Rules

Switch Rules

Executing Switch Example

The break Statement

default case

Other Expression Types

When Not to Use Switch

Author: Richard Maclin


Home Page:

Download presentation source