{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS31-2

CS31-2 - CS 31 Introduction to Computer Science I Topic 2...

This preview shows pages 1–13. Sign up to view the full content.

CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-1 CS 31 : Introduction to Computer Science I Topic 2 Flow of Control

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

View Full Document
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-2 Flow of Control Boolean Expressions Are also called conditional expressions Use logical operands and operators Similar to arithmetic expressions Evaluate to true or false Used for selection and repetition
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-3 Flow of Control Logical Operators Arithmetic comparison ==, !=, <, >, <=, >= NOTE: == Logical combination !, &&, | |

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

View Full Document
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-4 Flow of Control Arithmetic Comparison Ops Compare two arithmetic values May be signed or unsigned Result is true or false Examples: 25 <= 40 true 59.374 == 95.81 false
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-5 Flow of Control Logical Combination Ops Unary: ! Not Binary: && And | | Or

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

View Full Document
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-6 Flow of Control Logical Operators: ! (Not) Unary: Opposite of value !true = false !false = true
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-7 Flow of Control Logical Operators: && (And) Binary: True only if both operands true false && false= false false && true = false true && false = false true && true = true

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

View Full Document
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-8 Flow of Control Logical Operators: | | (Or) Binary: True only if either operand is true false | | false = false false | | true = true true | | false = true true | | true = true
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-9 Flow of Control Precedence Hierarchy of operators Determines evaluation order without ( ) 18 levels in C++ (Depending on author) Use parentheses to override Use parentheses for clarity

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

View Full Document
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-10 Flow of Control Precedence Levels (Partial) Postfix increment and decrement Prefix increment and decrement, Unary + and -, Not (!) Multiplicative operators (*, /, %) Additive operators (+, -) I/O operators (<<, >>) Magnitude comparison (<, >, <=, >=) Equality comparison (==, !=) And (&&) Or (| |) Assignment (=)
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A. Rohr All Rights Reserved JAR 2-11 Flow of Control Short-Circuit Evaluation Used for && and | | operators May not evaluate second operand Evaluated only if needed Examples: false && anything false true | | anything true

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

View Full Document
CS 31: Introduction To CS I Topic 2: Flow of Control 9/2009 John A.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}