+ 1
Can someone explain to me the following?
var a = 0 ; for ( i = 4 ; i < 8 ; i ++ ) { if ( i == 6 ) { continue ; } a+ = i ; } document.write ( a ) ;
4 Answers
+ 1
Please tag "web" or "Javascript".
Print i to console at the end of the loop to see what is happening.
+ 1
Abdellah
if 'i' is 6 then don't add it. It means
a = 4 + 5 + 7 = 16
continue is use to skip current iteration
+ 1
Thanks for the help, I really appreciate your supportđ€đ€
0
Here it calculates the sum of the number of i without adding the number 6 because the condition that if i is equal to 6 then it continues to the next number, i.e. in increment i(i++) from where the number is 7 and the last takes all the numbers of i which are lower than 8 according to the condition of for and therefore here i starts with 4 from where a=4+5+7=16
i=4 is true because 4<8
i=5 is true because 5<8
i=7 is true because 7<8
For i=6 the condition if a ignores it continuing to the next number from where the result that will be displayed on the screen is 16