Program Flow Flashcards
What’s the flow of a program?
The order that the steps are carried out in.
How can you control the program flow?
Using selection statements: IF statements and CASE statements.
What is an IF statement?
Allows you to check if a condition is true or false, and carry out different actions depending on the outcome.
What is a nested IF statement?
Putting another IF statement inside another.
What does a nested IF statement allow?
- check more conditions once you’ve established the previous condition is true.
What is IF-ELSEIF statement?
Used to check multiple conditions. They’re different from nested IF statements as they only check more conditions if the previous condition is false.
What is a SWITCH-CASE statement?
Instead of checking if a statement is true or false, it checks if a variable has specific values.
What are SWITCH-CASE statements used for?
When you want a program to perform different actions for different values of the same variable.
How are SWITCH-CASE statements different to IF statements?
They have a smilier structure but SWITCH-CASE statements give a neater way to test different values of a variable, this makes them easier than ELSEIF statements to maintain.
What is a disadvantage of SWITCH-CASE statements?
They can only check the value of one variable.
What is a FOR loop?
It’ll repeat the code inside a fixed number of times. The number of times that the code repeats will depend on an initial value, end value and the step count.
What makes SWITCH-CASE statements more robust?
They include a ‘default’ case which tells the program what to do if none of the other cases are correct.
What are DO UNTIL loops?
- controlled by a condition at the end of the loop.
- keep going until the condition is true (i.e. while it’s false)
- always run the code inside them at least once
- you get an infinite loop if the condition is never true
What are WHILE loops?
- controlled by a condition at the start of the loop
- keep going while the condition is true (i.e. until it’s false)
- never run the code inside them if the condition is initially false
- you get an infinite loop is the condition is always true.
What are DO WHILE loops?
- controlled by a condition at the end of the loop
- keep going while the condition is true (i.e. until it’s false)
- always run the code inside them at least once.
- you get an infinite loop if the condition is always true.