Lec5 - Lecture 5 Boolean if else else operators Control...

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

View Full Document Right Arrow Icon
Lecture 5 if, else, else if statement blocks 1 Lecture 5 Boolean operators Control statement blocks if else if else
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 5 if, else, else if statement blocks 2 Boolean operators The nine Boolean operators < less than <= less than or equal to > greater than > = greater than or equal to = = equal to (easily forgotten – don’t use one = sign, or the consequences will be severe!) ! = does not equal && and (easily forgotten) || or ! not
Background image of page 2
Lecture 5 if, else, else if statement blocks 3 Two examples (1,2) x = 1; y = 2; z = 3; if (x<y) a=5; if (y<z) b=5; if (z>y && y>x) a=1; if (z<y || x<y) b=1; if (z != x) b=2; // what do a and b equal? x = 1; y = 2; z = 3; if (y<x) { a=5; b=5; } else if (z>y && y>x) { a=1; b=2; } else { a = 3; b = 3; } // what do a and b equal? a=1 and b=2 a=1 and b=2 X X
Background image of page 3

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

View Full DocumentRight Arrow Icon
Lecture 5 if, else, else if statement blocks 4 A complex example if ( ( ( x<y ) && ( y>z ) ) || ( ( z>x ) && ( y>x ) ) || ( ( x<z ) && ( y>z ) ) ) Is this true or false? x = 1; y = 2; z = 3; T T T T F F T F T
Background image of page 4
Lecture 5 if, else, else if statement blocks 5 { double radius, //Radius of the cylinder height, //Height of the cylinder volume; //Volume of the cylinder
Background image of page 5

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

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

This note was uploaded on 02/26/2008 for the course ENGR 1 taught by Professor X during the Spring '07 term at Lehigh University .

Page1 / 8

Lec5 - Lecture 5 Boolean if else else operators Control...

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

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