CS31-2

CS31-2 - CS 31: Introduction To CS I 9/2009 John A. Rohr...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 2-1 CS 31 : Introduction to Computer Science I Topic 2 Flow of Control CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights JAR 2-3 Flow of Control Logical Operators Arithmetic comparison ==, !=, <, >, <=, >= NOTE: == Logical combination !, &&, | | CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights JAR 2-5 Flow of Control Logical Combination Ops Unary: ! Not Binary: && And | | Or CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 2-6 Flow of Control Logical Operators: ! (Not) Unary: Opposite of value !true = false !false = true CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights 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 CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights 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 9/2009 John A. Rohr All Rights 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 CS 31: Introduction To CS I 9/2009 John A. Rohr All Rights JAR 2-12 Flow of Control Integers as Boolean Values Used in C language Available in C++ 0 false Any nonzero value true Compiler generates 1 for true CS 31: Introduction To CS I 9/2009 John A....
View Full Document

This note was uploaded on 10/08/2011 for the course CS 31 taught by Professor Melkanoff during the Fall '00 term at UCLA.

Page1 / 65

CS31-2 - CS 31: Introduction To CS I 9/2009 John A. Rohr...

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

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