Control structures Flashcards

1
Q

Give an example of an instruction that is a definition.

A

a ← 4

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

Give an example of an instruction that is a statement.

A

Print “Hello.”

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

What is the difference between a definition and a statement?

A

Definition = an instruction that assigns a value to a variable.
(a ← 4)

Statement = executes a single action.
(Print “Hello.)

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

How does a sequence differ from an iteration?

A

Sequence = executes line-by-line.
(Printing an element from an array)

Iteration = executes a number of
times that depends on if a condition is met
(Multiple statements being printed after the conclusion of a for loop)

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

What is the difference between a WHILE loop and a DO/WHILE loop?

A

A WHILE loop runs code as long as a condition is true but may not run at all if the condition isn’t met initially.

In contrast, a DO/WHILE loop always runs at least once, regardless of the initial condition.

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