8-IfElse - ControlStructures: DecisionMakingwith IF Control...

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

View Full Document Right Arrow Icon
Control Structures: Decision Making with IF
Background image of page 1

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

View Full DocumentRight Arrow Icon
Control Structures C statements can make decisions via Selection structures The if selection statement performs (selects) an action if a condition is true skips the action if the condition is false . The if else selection statement performs an action if a condition is true performs a different action if the condition is false . The switch selection statement performs one of many different actions depending on the value of an expression.
Background image of page 2
Decision Making: Equality and Relational Operators Example: determine if a person’s grade on an exam is greater than or equal to 60 if it is, print the message “passed.”
Background image of page 3

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

View Full DocumentRight Arrow Icon
Control Structures (Cont.) FLOW CHARTS for Selection Structures: The diamond symbol , also called the decision symbol, indicates that a decision is to be made. Condition true? Action (s) to take if true
Background image of page 4
The if Selection Statement C syntax: if (condition) { /* begin condition*/ stmnt 1; stmnt 2; …. } /* end condition */ Condition true? Action (s) to take if true CS211 Rule: Line up the brackets and provide comments!
Background image of page 5

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

View Full DocumentRight Arrow Icon
Conditional Operators for IF  and other conditional statements if  ( grade >=  60  ) 
Background image of page 6
The if Selection Statement
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 / 25

8-IfElse - ControlStructures: DecisionMakingwith IF Control...

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