Devtools Tech Logo
0
0
0

In the above code snippet, x = 1 initially and it follows the following steps afterwards

  1. Check against the limit (6)
  2. Assign x the new value
  3. Increment x with 2
  4. Repeat
First iteration [x = 1] :

Step 1 -- 1 < 6 -- true
Step 2 -- x = 1 * 1 -- 1
Step 3 -- x += 2 -- 1 += 2 -- 3

Second iteration [x = 3]:

Step 1 -- 3 < 6 -- true
Step 2 -- x = 3 * 3 -- 9
Step 3 -- x += 2 -- 9 += 2 -- 11

Third iteration [x = 11]:

Step 1 -- 11 < 6 -- false

So, loop breaks now and 11 will be the final value of x

For useful and amazing frontend and programming tutorials: https://bit.ly/devtools-yt