Flow Control Flashcards

1
Q

What do smart programs use to make decisions on whether to run lines of code or skip them?

A

Booleans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does an if statement do?

A

If statements are lines of code that respond to different situations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the values that decide whether a code block runs or not?

A

Conditions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we distinguish code blocks?

A

Code blocks will have an indentation of two spaces. Lines with the same indentation belong to the same code block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What do we call the code that is indented after an if statement?

A

A code block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the maximum number of lines that a code block can have?

A

As many as we want

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why do we use comparisons with if statements?

A

To make smarter decisions about running or skipping code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What do we use comparisons with == for in an if statement?

A

To run or skip coe depending on whether two values are the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What operator runs an if statement’s code block when two values are different?

A

!= The inequality operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we avoid rewriting the same comparison multiple times?

A

We can save its result in a variable and reuse the variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s the keyword that decides if a code block should run or not?

A

if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What kind of value do we use as a condition for an if statement?

A

Boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do we call statements that run or skip code depending on a condition being True or False?

A

Conditional statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why are comparisons better conditions than just True or False?

A

Because the value of the variables can change, so it may run or skip a code block depending on the value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where is an else statement positioned?

A

The else statement of an if/else statement always goes at the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Does an else statement need a condition?

A

No. The else statement doesn’t need its own condition. That’s because it handles the cases where the if’s condition is False.

17
Q

What is an else statement?

A

A conditional that runs when the if statements condition is False.

18
Q

Why can we consider the else statement a default response?

A

The else statement’s code block runs for all the cases for which if statement returns False.

19
Q

What does elif stand for?

20
Q

What is the function elif used?

A

elif is used when there is a second condition to be checked when the condition of the if block was not met.

21
Q

Where does the elif statement go?

A

After the if statement and before the else statement.

22
Q

What happens when the if statement and elif statement conditions return False

A

The else statement code block runs

23
Q

What operators allows us to program an if statement with multiple conditions?

A

The and and or operators.

24
Q

What is the and operator for?

A

For linking multiple conditions.

25
When does the and operator skip the code block?
When one or more conditions are false
26
What is the difference between the and and or operators?
And runs code if all conditions are met. Or runs code if one of the conditions are met.
27
When does the or operator skip the code block?
Only when all linked conditions are False
28
Why doesn't the else statement have its own condition?
Because its condition is the opposite of the if statement's condition.
29
Which operator do we use when we want to run code only when all conditions are True?
And
30
What is self-assignment?
It is when we set a variable to its own value.
31
What do self-assigning variables allow us to do?
They allow us to track data that changes over time.
32
What operator do we use to subtract a number from a variable's value?
-=
33
Which operator adds to a variable's value?
+=
34
How does a while loop function?
A while loop repeats its code block while its condition is True.
35
How do we know when a while loop will stop?
By checking its condition.
36
What do we call a loop that repeats itself forever?
An infinite loop
37
What controls how many times a while loop repeats itself?
The counter variable. This is a variable set to a number.
38
What's the name of the variable that we use to count the number of times a loop repeats itself?
A counter variable