How to Stop an Infinite Loop
- 1). Open the source code in the programming software.
- 2). Identify the infinite loop in the source code. During an infinite loop a program often does not return output or accept input. Start by looking at the code in the area after the last successful input or output action occurred.
- 3). Insert a line within the loop structure to determine the value of the variable such as in the following Basic language code:
while x < 10
print x /* line added to monitor variable*/
end while - 4). Execute the code and monitor the value of the variable. Determine why the variable is not reaching the value required to fulfill the conditional statement.
- 5). Modify the source code to satisfy the loop's condition to exit:
while x < 10
print x /* line added to monitor variable*/
x = x + 1
end while - 6). Execute the source code and confirm that the infinite loop has been resolved.
- 7). Remove the line of code added to debug the infinite loop.
Source...