02 Section 5 - Program flow, Boolean operators and Arrays Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What do IF statements allow a programmer to do?

A

To check if a condition is true or false, and carry out different actions depending on the outcome

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

What structure do IF statements normally have?

A

IF … THEN:

ElSE:

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

When is ELSE not needed in an IF statement?

A

If there is nothing for the program to do when the condition is false then leave out the ELSE part

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

What is a nested IF statement?

A

A more complex IF statement, made by putting one IF statement inside of another

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

What do nested IF statements allow you to do?

A

-check more conditions once you have established the previous condition is true

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

What are IF-ELSEIF statements used for?

A

To check multiple conditions

-only check more conditions if the previous condition is false

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

What are SWITCH-CASE statements?

A

statements that can check whether a variable has specific values

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

When are SWITCH-CASE statements used?

A

When you want a program to perform different actions for different values of the same variable

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

What is the structure of SWITCH-CASE statements?

A

SWITCH … :
CASE … :
CASE … :
ENDSWITCH

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

What is the drawback of SWITCH-CASE statements?

A

They can only check the value of one variable

IF-ELSEIF statements can check if multiple conditions are true

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

What are FOR loops?

A

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)

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

What is the structure of FOR loops?

A

FOR i in RANGE():

NEXT i

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

What are the different types of loops you can have that are controlled by conditions?

A

REPEAT … UNTIL

WHILE

DO WHILE

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

What is an example of a count-controlled loop?

A

FOR loops

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

What are the features of REPEAT loops?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the features of WHILE loops?

A
  • controlled by a condition at the start of the loop
  • keep going while the condition is true (i.e. until it is false)
  • never runs the code inside it if the condition is initially false
  • get an infinite loop if the condition inside is always true
17
Q

What are the features of DO WHILE loops?

A
  • controlled by a condition at the end of the loop
  • keep going while the condition is true (i.e. until it’s false)
  • always runs the code inside it at least once
  • get an infinite loop if the condition is always true
18
Q

What is the structure of a REPEAT loop?

A

REPEAT

UNTIL condition

19
Q

What is the structure of a WHILE loop?

A

WHILE condition

ENDWHILE

20
Q

What is the structure of a DO WHILE loop?

A

DO

WHILE condition

21
Q

Whant are the 3 different Boolean operators?

A

AND
OR
NOT

22
Q

Why are Boolean operators used in conditions?

A

Boolean operators can be used to make all the different selection and iteration statements more efficient and versatile

23
Q

What are examples of selection statements?

A

IF-THEN-ELSE statements
Nested IF statements
IF-ELSEIF statements
SWITCH-CASE statements

24
Q

What are examples of iteration statements?

A

FOR loops
REPEAT loops
WHILE loops
DO WHILE loops

25
Q

What is an array?

A

It’s a data structure that can store a collection of data values all under one name
LISTS

26
Q

What is each piece of data in an array called?

A

an element

27
Q

How can an element of an array be accessed?

A

-each element can be accessed using its position (or index) in an array

28
Q

When should arrays be used?

A

When you have lots of related data that you want to store and it doesn’t make sense to use separate variables

29
Q

How do you create an array?

A
ARRAY nameofarray[numberofvaluesinarray]
nameofarray[0] = data
nameofarray[1] = data 
nameofarray[2] = data
...
30
Q

How do you retrieve values from an array?

A

print(nameofarray[element’sposition])

31
Q

How do you change elements in an array?

A

nameofarray[element’sposition] = newdata

32
Q

What are two-dimensional arrays?

A

Like lists of lists, where each element of the one-dimensional array also has a one-dimensional array

33
Q

What is the position of an element in a two-dimensional array written as?

A

[a, b] or [a][b]
where a represents the position in the one-dimensional array that the element is in
and where b represents its position within that one-dimensional array