Conditionals Conditional statements, called conditionals for short, are statements in the if-then or...
-
Upload
stewart-shields -
Category
Documents
-
view
218 -
download
0
description
Transcript of Conditionals Conditional statements, called conditionals for short, are statements in the if-then or...
![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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/1.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/2.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/3.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/4.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/5.jpg)
![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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/6.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/7.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/8.jpg)
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,](https://reader036.fdocuments.net/reader036/viewer/2022081811/5a4d1b7c7f8b9ab0599b997b/html5/thumbnails/9.jpg)
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)