Coding - practical 8 Flashcards

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

What is the general form of a while loop?

A

while (condition) {
statements
}

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

Describe what the condition statements do in a while loop.

A
Condition = when should the loop run
Statements = what should the loop do each time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When does the condition of the while loop get checked?

A

The condition of the while loop always gets checked before the loop starts!

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

How is a do while loop different to a while loop?

A

Almost exactly the same BUT
- The condition is checked at the end
- Will always run at least once!
(the only difference is at what point the condition is checked)

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

What is the general form of a for loop?

A

for (initialisation; condition; increment) {
statements
}

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

Describe the initialisation in a for loop.

A

This is where we can initialise our variable and is our for-loops start point.

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

Describe the condition in a for loop.

A

Sets the condition that controls whether the loop should continue or stop.

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

Describe the increment in a for loop.

A

What do we want to do each time our loop runs, usually we change the value of our variable in some way.

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

What can you use to increment or decrement by 1?

A

++ and –

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

When is it more appropriate to use a do while loop?

A

When the outcome of the condition is controlled by the statements within the loop. Or that you need to always do something once regardless of the condition.

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