cs31 lecture 17

Executed is 36 more on conditions x can use standard

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: aves the value of foo Example: unchanged unchanged 35 Control structure: if-then-else x Syntax in C++: IIf (<condition>)
 f <instructions1> <instructions1> [else [else <instructions2>] <instructions2>] x Instructions are usually a block, that is { … } x <condition> is an expression When it evaluates to 0 or ‘false’, then <instructions1> is not When executed, and if there is a else, then <instructions2> is executed executed, When it evaluates to any value not 0, or ‘true’, then <instructions1> When is executed is 36 More on conditions x Can use standard operators for comparison of values < or > or <= or >= or == Be careful: = is assignment, == is comparison 12 < 12 is a false expression 12 < 13 is a true expression 12 is a non-0 expression (hence “true”)
 x Conjunction/disjunction can be expressed with logical Conjunction/disjunction operators operators && for logical and || for logical or 37 Loops x Critical control-flow structure: iterative/repetitive process x Almos...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online