WorksheetsSLG IPC Week 4
Total questions: 12
Worksheet time: 15mins
Did you turn memes on?
Yes, of course. Who could forget the memes?
What memes? I don't remember seeing that option.
I saw the option, but didn't turn them on.
They're already on by default.
What does default do in a switch statement?
Executes code regardless if a case matches or not.
Executes code in the event no case is matched.
Exits from the switch construct.
What's a switch statement?
if (minutes > 1)
s = 's';
else
s = ' ';
Can be rewritten as?
s =
minutes > 1 ? 's' : ' ';
s =
if (minutes > 1)
's' : ' ';
s =
minutes > 1 ? ' ' : 's';
s = 's' : ' ';
Pick the odd one out.
While
Do while
For
Switch
What is the difference between a do while and a regular while loop?
Write an example of a for loop.
Which for loop uses a flag properly?
for (int i = 0; i < 10 && done == 0; i++)
for (int flag = 0; flag < 10; flag++)
for (i = 0; flag == 0; i++)
for (int i = 0; i < 10 && i == 0; i++)
Why shouldn't you use break outside of a switch statement?
Because my professor told me so.
Because it violates the single-entry single-exit principle.
Because it would give me an error.
Because it can only be used in a switch statement.
What class of construct does the flowchart represent?
(a)
What class of construct does this flowchart represent?
(a)
Do you remember how to write a switch statement? Write an example of one now.
For simplicity you can use placeholders like condition, constant, sequence.
What is an infinite loop and why is it bad?
