The best way to figure it out is to go through it by hand for a few manageable values of N
. For instance, if N
is 2:
i == 0
and0 < 2
→ print"hello"
, incrementi
i == 1
and1 < 2
→ print"hello"
, incrementi
i == 2
and→2 < 2
while
-loop condition is no longer satisfied → loop ends
So for N = 2
, "hello"
is printed 2 times. See the pattern?