Ask coding questions

← Back to all posts
infinite loop
LukeWright (287)

so sometimes when i run this code, it goes into an infinate loop and i cannot figure out why. can someone help me?

Answered by 19wintersp (1142) [earned 5 cycles]
View Answer
19wintersp (1142)

Your while loop on line 16 will never exit as its condition will never be invalidated: counter is never modified inside of it. You should indent line 32 so that it is inside the loop.

19wintersp (1142)

@LukeWright You need to add counter += 1 to the loop on line 44 as well.

SamuelPKuld (12)

Hi, can you please specify which while statement is looping infinitely?

LukeWright (287)

thats the thing. i have no idea @SamuelPKuld