0
Why the answer is 2 instead of 1 here?
Fill in the blanks to print EVEN values from 0 to 20 using for a loop: var x= 0 for ( ; x <= __; x +=_) { document.write(x); }
3 odpowiedzi
+ 1
Because it is more efficient to increase <x> value by two. The next even number is always 2 number away from the first anyways. If <x> value was incremented by 1, then there will be more iterations needed, and there will be a need to check whether <x> was even or odd.
The same method can also be used to print odd values. But initial value of <x> must be an odd value too.
(Edit)
Please tag a relevant language -> Javascript
+ 1
Thank you
+ 1
No problem 👌