Chap4 - Chapter 4 1 Outline Selection Criteria The...

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

View Full Document Right Arrow Icon
1 Chapter 4
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline ± Selection Criteria ± The if-then-else Statement ± Nested if Statements ± The switch Statement ± Applications ± Common Programming Errors
Background image of page 2
3 Selection Criteria ± if-else statement: implements a decision structure for two alternatives Syntax: if (condition) statement executed if condition is true; else statement executed if condition is false;
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Selection Criteria (continued) ± The condition is evaluated to its numerical value: ± A non-zero value is considered to be true ± A zero value is considered to be false ± The else portion is optional; it is executed only if the condition is false ± The condition may be any valid C++ expression
Background image of page 4
5 Selection Criteria (continued) ± Relational expression: compares two operands or expressions using relational operators
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Selection Criteria (continued) ± Relational expressions are evaluated to a numerical value of 1 or 0 only: ± If the value is 1, the expression is true ± If the value is 0, the expression is false ± char values are automatically coerced to int values for comparison purposes ± Strings are compared on a character by character basis; the string with the first lower character is considered smaller
Background image of page 6
7 Selection Criteria (continued) Examples of string comparisons:
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Selection Criteria (continued) ± Logical operators ± AND ( ): condition is true only if both expressions are true ± OR ( || ): condition is true if either one or
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2009 for the course CSC 101 taught by Professor Betancourt during the Spring '09 term at CUNY City.

Page1 / 31

Chap4 - Chapter 4 1 Outline Selection Criteria The...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online