Download presentation
Presentation is loading. Please wait.
Published byYohanes Budiono Modified over 6 years ago
1
Complex Conditionals Human languages are ambiguous
Computer languages must be precise Complex Conditionals Complete this conditional statement: IF it snows and the temperature is below 32 _________________ ELSE _________________ CSD Code Studio Level 9
2
Review Boolean: true or false
Expression: something you evaluate to get an answer like 1+5 or x < 7 Conditional or Boolean expression: an expression with a Boolean result Conditional statement: chooses what to do based on a conditional expression
3
These are conditional statements
Complex conditional
4
Write your own conditional statements in code form using Boolean expressions:
If the bell rings you should log out. You can buy french fries if you have at least 50 cents. If the bird sprite is on the top half of the screen, rotate it by 10. Point out ambiguities in English that make it difficult to know exactly what the code should do Point out that variables would need to be declared and assigned in order to use these conditionals.
5
Conditional statements in code form using Boolean expressions:
If the bell rings you should log out. You can buy french fries if you have at least 50 cents. If the bird sprite is on the top half of the screen, rotate it by 10. Ask: is each condition a Boolean expression? How do you decide on variable names?
6
These are more Boolean functions in CodeLab
mouseDidMove() Returns true if the mouse did move if(mouseDidMove()) {} mouseWentDown(side) Returns true once when the specified mouse button is pressed down if(mouseWentDown("left")) {} mouseWentUp(side) Returns true once when the specified mouse button is released if(mouseWentUp("left")) {} keyWentDown(key) Returns true once when the specified key is pressed down if(keyWentDown("e")) {} keyWentUp(key) Returns true once when the specified key is released if(keyWentDown("m")) {}
7
Video (4:18)
8
What happens? When do the gear rotate? When the space key is pressed down (Stage 9 puzzle 3) What happens if the space key is not pressed down? Nothing, the gears stay still unless there is other code we cannot see.
9
What happens? What’s the difference between this code and the last one? The gears always move but they change direction if the space key is pressed down.
10
Work in code studio Stage 9
Human languages are ambiguous Computer languages must be precise
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.