Control structures Flashcards
Give an example of an instruction that is a definition.
a ← 4
Give an example of an instruction that is a statement.
Print “Hello.”
What is the difference between a definition and a statement?
Definition = an instruction that assigns a value to a variable.
(a ← 4)
Statement = executes a single action.
(Print “Hello.)
How does a sequence differ from an iteration?
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)
What is the difference between a WHILE loop and a DO/WHILE loop?
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.