[Solved] How does this while block work? [closed]


result and counter are separate variables with different goals in this code.

counter is incremented like

counter += 1

so that eventually the while condition

while (counter<10)

will be satisfied and the code will cease to execute.

As for result, each time the code in the while block is executed, result is updated by multiplying by 2.

result = result*2

It is ‘updated’ because the variable result was initialized outside the while loop but is accessible by it. With the above statement, it is taking the existing result variable and multiplying it by 2 then storing it back in result.

10

solved How does this while block work? [closed]