Sequence, selection and iteration Flashcards

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

What are the three basic control structures used in programming?

A

Sequence, selection and iteration

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

What are the three operators used in Boolean expressions?

A

AND, OR, NOT

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

What is Sequence?

A

The statements are executed one by one in the order they are written
e.g.
mark1 = 78
mark2 = 67
total = mark1 + mark2
average = total / 2
print(average)

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

What is Selection?

A

An IF statement is a selection statement
The next statement to be executed depends on whether the condition being tested is True or False
e.g.
if average >80 then
print(“Distinction”)
else
print(“Pass)
endif

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

Give an example of a Boolean expression

A

average >= 80
The outcome will always evaluate to TRUE or False

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

What are the comparison operators?

A

== equal to
!= -not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to

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

Why is = not used to mean equal to?

A

A single = is used for assignment - e.g. age = 14

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

What is Iteration?

A

a process wherein a set of instructions or structures are repeated in a sequence a specified number of times or until a condition is met
e.g.
repeat
<statements>
until <condition></condition></statements>

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

What are three types of programming loops?

A

FOR loop, WHILE loop, DO WHILE loop

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

When to use for loops

A

When you want to execute the loop a specified number of times
e.g.
total = 0
for i = 1 to 7
dailyTempurature = input()
total = total + dailyTempurature
next i
averageWeeksTemp = total / 7
print(averageWeeksTemp)

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

When to use while loops

A

When you want to execute the loop while a certain condition is true
e.g.
password = input(“Please enter password: “)
while password != “jd8UpP2+d”
password = input(“Invalid password - try again”)
endwhile
print(“Correct password”)

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

What is an infinite loop?

A

If a loop continues forever and there is no way to way to exit it, it is called an infinite loop

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

When to use do … until loops

A

When you want to execute the loop until a certain condition is True
The loop will always execute once
The condition is tested at the end of the loop
e.g.
password = “ “
do
password = input(“Invalid password - try again”)
until password == “jd8UpP2+d”
print(“Correct password”)

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

What loop should you use for this situation:
Ask a user to enter their name - if they don’t enter a name longer than one letter, then keep on asking them to enter their name

A

DO WHILE loop

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

What loop should you use for this situation:
Count from 1 to 100

A

For loop

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

What loop should you use for this situation:
Repeatedly check the state of a game to see if one of the players has won

A

WHILE loop