user3253832
user3253832

Reputation:

Testing for an infinite loop +java

I want to know (for exam questions) if num-- is commented out, will it cause an infinite loop. So I will try this and will get an infinite loop, which means I have to close down Eclipse and start up again. There must be a simpler way to test for an infinite loop.

package doWhile_loop;

public class DoWhileLoop {
    static int num = 20;

    public static void main(String[] args) {
        do {
            System.out.print("\t"+num /*num--*/);}//num-- commented out to test                           
        while(num >10);
    }

}

Upvotes: 0

Views: 211

Answers (2)

Andrew Gies
Andrew Gies

Reputation: 719

You shouldn't need to close eclipse. If you look in the top right corner of your console box when there is a running program, you can halt and shut down the process by clicking the little red stop button. That should end even an infinite loop. See the image below:

Screenshot depicting eclipse console with red button described above.

As long as you have a running process created by eclipse, that button will be enabled, and you can click it at any time.

Upvotes: 1

Saurabh Sharma
Saurabh Sharma

Reputation: 509

In your eclipse there is a Red Button. You can press that for terminating the program.

Upvotes: 0

Related Questions