Back to questions
JuniorTheoryCommon
What does the program print?
var count = 0
repeat {
count += 1
} while count > 5
print(count)1
- Expecting
0: treatingrepeat-whilelikewhile.repeatruns the body first and checks the condition after it, so the body always runs at least once. - Expecting
6: reading the loop as "repeat untilcount > 5". It repeats while the condition is true, and here it is false after the first pass.
- What does the program print if the loop is rewritten as
while count > 5 { count += 1 }? - When is
repeat-whilea better fit thanwhile?