The result should be 20.. isn't it? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

The result should be 20.. isn't it?

//because the loop should count to stop at 5 after then it will count but here is( i<7)? so it will count till it goes up to 5? var sum = 0; for( i=4; i<7; i++){ if(i==6){ continue; } sum+=i; } alert(sum); /* 0+4=4; 4+4=8; 8+4=12; 12+4=16; 16+4= 20; */

15th Dec 2022, 11:06 AM
Sony
Sony - avatar
6 Antworten
+ 1
i=4,sum=0 sum=0+4; i=5,sum=4 sum=4+5; i=6 is skipped over and i=7 doesnt pass the test neither of em gets to be added to sum, loops ends. so sum=9
15th Dec 2022, 11:39 AM
Arturop
Arturop - avatar
+ 1
then share the code link, there might be something else
16th Dec 2022, 8:31 AM
Arturop
Arturop - avatar
0
But the result showing something different.. it's 16 in codeground..
16th Dec 2022, 8:20 AM
Sony
Sony - avatar
0
Okay
16th Dec 2022, 10:18 AM
Sony
Sony - avatar
0
It was a great mistake from my end .... Thank you so much..!
16th Dec 2022, 10:21 AM
Sony
Sony - avatar
0
I posted multiple questions that's why might be happened in this way..
16th Dec 2022, 10:22 AM
Sony
Sony - avatar