This code is designed to display prime numbers, I can not understand how it works step by step:
nextPrime: for (var i = 2; i < 10; i++) { for (var j = 2; j < i; j++) { if (i % j == 0) continue nextPrime; } alert( i ); // ΠΏΡΠΎΡΡΠΎΠ΅ } Cycle is running for i, i.e.
- there is a check j <i, in this case it is wrong 2 <2
- the alert goes further and displays 2
- i increases by 1
- there is a check 2 <3, passes further
- remains remains 1
- alert (3) is running
- variables increase by 1
- 3 <4
- alert (4)
- still increasing 4 <5
- alert (5)
etc.
But it's not like that.
In theory, the step: i/j++ is performed after the body at each iteration, but before checking the condition, if you follow the syntax of the language, therefore, the check will fail and all numbers up to 9 will be displayed; but in fact it is not.
I am new to JS, but I would like to immediately understand what was happening ... Can you please explain why this is happening?
This question is intended to understand the sequence of actions in cycles.
continuewith the label, a little different all the same "for". - Rolandiuscontinue LABEL;andcontinue;- these are different teams. - Qwertiy β¦