Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
let grade = "B"
switch grade {
case "A":
print(5)
case "B":
print(4)
case "C":
print(3)
default:
print(2)
}4
- Expecting
4 3 2, as in C, where execution falls into the branches below. A Swift branch ends on its own; onlyfallthroughmoves into the next one. - Expecting
defaultto run after the matching branch as well. It runs only when nocasefits the value.
- What does the program print if you add
fallthroughafterprint(4)? - How would you make one branch handle both
"B"and"C"?