Computer Science, asked by gkkuchipudi, 1 year ago

var x = 1; for (var i = 0; i < 3; i++) { x += 5 * i; } console.log(x);


adanperez1738: what is the name of this subject and how do you solve or learn it
adanperez1738: contact me @ [email protected] i really want to find out

Answers

Answered by harshash12
3
the answer is
5*0=0
5*1=5
5*2=10
Answered by homosapiens45
3

Given : x = 1


Iteration 1 :


for( i=0 ; i < 3 ; i++ )


x + = 5 * i ( x = x + 5 * i )


= 1 + = 5 * 0 ( x = 1 + 5 * 0 )

x = 1


Iteration 2 :


for ( i=1 ; i < 3 ; i++ )


x + = 5 * i


= 1 + = 5 * 1 ( x = 1 + 5 * 1 )

x=6


Iteration 3 :



for ( i=2 ; i < 3 ; i++ )


x + = 5 * i


6 + = 5 * 2 ( x = 6 + 5 * 2 )

x=16



When proceeding for next iteration ie; i=3 checks with the for loop for ( i = 3 ; 3 < 3 ; i++ )

It fails the condition in for loop,Thus Exit the Loop and moves to the next line Console.log(x)


Now the Current value for x=16


Hence the output is x = 16.

Similar questions