Flow Control Flashcards
What do smart programs use to make decisions on whether to run lines of code or skip them?
Booleans
What does an if statement do?
If statements are lines of code that respond to different situations.
What are the values that decide whether a code block runs or not?
Conditions
How can we distinguish code blocks?
Code blocks will have an indentation of two spaces. Lines with the same indentation belong to the same code block.
What do we call the code that is indented after an if statement?
A code block
What is the maximum number of lines that a code block can have?
As many as we want
Why do we use comparisons with if statements?
To make smarter decisions about running or skipping code
What do we use comparisons with == for in an if statement?
To run or skip coe depending on whether two values are the same
What operator runs an if statement’s code block when two values are different?
!= The inequality operator
How can we avoid rewriting the same comparison multiple times?
We can save its result in a variable and reuse the variable.
What’s the keyword that decides if a code block should run or not?
if
What kind of value do we use as a condition for an if statement?
Boolean
What do we call statements that run or skip code depending on a condition being True or False?
Conditional statements
Why are comparisons better conditions than just True or False?
Because the value of the variables can change, so it may run or skip a code block depending on the value.
Where is an else statement positioned?
The else statement of an if/else statement always goes at the end.
Does an else statement need a condition?
No. The else statement doesn’t need its own condition. That’s because it handles the cases where the if’s condition is False.
What is an else statement?
A conditional that runs when the if statements condition is False.
Why can we consider the else statement a default response?
The else statement’s code block runs for all the cases for which if statement returns False.
What does elif stand for?
Else-if
What is the function elif used?
elif is used when there is a second condition to be checked when the condition of the if block was not met.
Where does the elif statement go?
After the if statement and before the else statement.
What happens when the if statement and elif statement conditions return False
The else statement code block runs
What operators allows us to program an if statement with multiple conditions?
The and and or operators.
What is the and operator for?
For linking multiple conditions.