In the second example, there are separate if statements that all get evaluated.
line 1 - step is 1
line 5 - step == 1 is true, so line 8 - step is incremented to 2
line 10 - step == 2 is true, so line 13 - step is incremented to 3
line 15 - step == 3 is true, so line 18, step is back to 1
back to line 4, step is 1