02 Section 5 - Program flow, Boolean operators and Arrays Flashcards
What do IF statements allow a programmer to do?
To check if a condition is true or false, and carry out different actions depending on the outcome
What structure do IF statements normally have?
IF … THEN:
ElSE:
When is ELSE not needed in an IF statement?
If there is nothing for the program to do when the condition is false then leave out the ELSE part
What is a nested IF statement?
A more complex IF statement, made by putting one IF statement inside of another
What do nested IF statements allow you to do?
-check more conditions once you have established the previous condition is true
What are IF-ELSEIF statements used for?
To check multiple conditions
-only check more conditions if the previous condition is false
What are SWITCH-CASE statements?
statements that can check whether a variable has specific values
When are SWITCH-CASE statements used?
When you want a program to perform different actions for different values of the same variable
What is the structure of SWITCH-CASE statements?
SWITCH … :
CASE … :
CASE … :
ENDSWITCH
What is the drawback of SWITCH-CASE statements?
They can only check the value of one variable
IF-ELSEIF statements can check if multiple conditions are true
What are FOR loops?
An example of count-controlled loops
They will repeat the code inside of them for a fixed number of times
-the number of times they are repeated depends on an initial value, end value and step count (can also be set as the program runs by using a variable as the number)
What is the structure of FOR loops?
FOR i in RANGE():
NEXT i
What are the different types of loops you can have that are controlled by conditions?
REPEAT … UNTIL
WHILE
DO WHILE
What is an example of a count-controlled loop?
FOR loops
What are the features of REPEAT 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 runs the code inside at least once
- you can get an infinite loop if the condition is never true