Back to questions
JuniorTheoryCommon
What does the program print?
for i in stride(from: 1, to: 7, by: 2) {
print(i, terminator: " ")
}1 3 5
- Expecting
1 3 5 7: treatingto:likethrough:. Withto:the end value is never part of the sequence, so the loop stops at5. - Expecting the sequence to start at
3: assuming a step is taken before the first value. A stride starts atfromitself.
- What does the loop print with
through: 7instead ofto: 7? - How would you count down from 5 to 1 with
stride?