Back to questions
JuniorTheoryCommon
What does the program print?
let out = "";
for (let i = 1; i <= 10; i++) {
if (i % 2 === 0) {
continue;
}
if (i > 7) {
break;
}
out += i;
}
console.log(out);1357
- Expecting
13579:breakleaves the whole loop, not just theifbraces. Ati = 9the loop ends, so9is never added. - Expecting
1:continuedoes not end the loop. It skips the rest of this iteration and goes on with the nexti, so every odd number up to7gets added.
- What does the program print if the two
ifblocks swap places? - What does the program print if
outstarts as0instead of""?