Presentation is loading. Please wait.

Presentation is loading. Please wait.

The C++ IF Statement Part 2 Copyright © Curt Hill

Similar presentations


Presentation on theme: "The C++ IF Statement Part 2 Copyright © Curt Hill"— Presentation transcript:

1 The C++ IF Statement Part 2 Copyright © 2004-2012 Curt Hill
Not much left should be merged into 1 or 3 Copyright © Curt Hill

2 What else is there to know?
More forms of the if? More forms of the condition? More Boolean information? Copyright © Curt Hill

3 Two forms of if statement
if (boolean) statement if (boolean) statement else statement Copyright © Curt Hill

4 The Else There is no THEN like in Pascal or BASIC The else is optional
The statement to do if condition is true immediately follows the parenthesized condition The else is optional Else is a reserved word and signals the start of the statement to execute if the condition is false The if without an else means else do nothing Copyright © Curt Hill

5 Compound statements Either the then statement or the else statement may be replaced with a compound statement In any combination Even the compound statement of an if may create local variables Their scope is confined to the compound statement Copyright © Curt Hill

6 Example Revisited Let’s redo the quadratic formula program
Copyright © Curt Hill


Download ppt "The C++ IF Statement Part 2 Copyright © Curt Hill"

Similar presentations


Ads by Google