conditionals conditional statements, called conditionals for short, are statements in the if-then or...
DESCRIPTION
Conditional Expressions in BYOB Are either TRUE or FALSE at that instant Pointed at both ends 3TRANSCRIPT
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”
Conditionals in BYOB• Conditionals evaluate the conditional expression to determine if it is
TRUE or FALSE
3
Conditional Expressions in BYOB• Are either TRUE or
FALSE at that instant• Pointed at both ends
Conditional Examples
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
Compound Conditional Example
Conditional controls• Other controls use conditions, too
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)