+ 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 ) ;

23rd Sep 2022, 1:45 PM
ab2coding
ab2coding - avatar
4 Answers
+ 1
Please tag "web" or "Javascript". Print i to console at the end of the loop to see what is happening.
23rd Sep 2022, 1:47 PM
Lisa
Lisa - avatar
+ 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
23rd Sep 2022, 3:12 PM
AÍąJ
AÍąJ - avatar
+ 1
Thanks for the help, I really appreciate your supportđŸ€đŸ€
23rd Sep 2022, 6:11 PM
ab2coding
ab2coding - avatar
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
23rd Sep 2022, 4:41 PM
ALI Moussa Kadjalla
ALI Moussa Kadjalla - avatar