+ 2

Could someone explain me how this code works line to line? Thanks.

for(var i=1;i<4;i++){ i=f(i); } function f(x){ return x+2; }

31st May 2018, 1:17 PM
Rastislav Romanec
Rastislav Romanec - avatar
4 Réponses
+ 2
FUNCTION SHOULD BE DECLARED FIRST BEFORE YOU CALL IT. THIS CODE WILL GENERATE ERROR.
31st May 2018, 1:21 PM
Meet Mehta
Meet Mehta - avatar
+ 2
IF IT IS DECLARED FIRST THAN YOUR CODE WILL LOOP FOUR TIME . EVERY TIME YOUR PROGRAM LOOP , IT WILL CALL FUNCTION f WHICH WILL INCREMENT CURRENT I VALUE AND STORE IT IN I.
31st May 2018, 1:26 PM
Meet Mehta
Meet Mehta - avatar
0
ok, but it will run at least once?
31st May 2018, 1:29 PM
Rastislav Romanec
Rastislav Romanec - avatar
0
NO. FOR GOD'S SAKE.
31st May 2018, 1:30 PM
Bebida Roja
Bebida Roja - avatar