conditionals conditional statements, called conditionals for short, are statements in the if-then or...

9
Conditionals •Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. •Examples: • “If the alarm goes off, I hit the snooze button” • “If I don’t have coffee, then Watch Out!” • “If the Red Sox win, then I am happy else I am sad”

Upload: stewart-shields

Post on 18-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

Conditional Expressions in BYOB Are either TRUE or FALSE at that instant Pointed at both ends 3

TRANSCRIPT

Page 1: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Conditionals• Conditional statements, called conditionals for short, are statements

in the if-then or if-then-else form.

• Examples:• “If the alarm goes off, I hit the snooze button”• “If I don’t have coffee, then Watch Out!”• “If the Red Sox win, then I am happy else I am sad”

Page 2: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Conditionals in BYOB• Conditionals evaluate the conditional expression to determine if it is

TRUE or FALSE

Page 3: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

3

Conditional Expressions in BYOB• Are either TRUE or

FALSE at that instant• Pointed at both ends

Page 4: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Conditional Examples

Page 5: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,
Page 6: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Booleans & Compound Conditionals• More than one conditional expression• “If the Red Sox win or the Yankees lose, I am happy”• “If the Red Sox win and the Yankees lose, I am very, very

happy!”

• The following are Boolean expressions:• ‘And’ – Both Expressions are true• ‘Or’ – At least one expression is true• ‘Not’ – If it’s true, then it becomes false; if it’s false, then it

becomes true

Page 7: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Compound Conditional Example

Page 8: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Conditional controls• Other controls use conditions, too

Page 9: Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: If the alarm goes off,

Classwork• Count up from 1 to 10• Use OR

• Use a variable keep track of where you are• Output the numbers using:

• Now count down from 10 to 1• Use the conditional loop you didn’t use above

• Now count up from 1 to 10, outputting only even numbers (using any method)