Multiple while loops inside a for loop

723 views Asked by At

I have created a for loop that detects the amount of devices connected to the computer. This then creates 2 JFrames, so every devices has it's own window. I now want to add data to those windows, so I created a while loop inside the for loop. But this stops the for loop from completing, meaning that only one JFrame shows data, and the second JFrame is not visible. If I remove the while loop from the for loop then 2 windows appear, but only one window is showing data, and the other window is blank. So the question is how do I get multiple while loops running to show data on multiple JFrames, based on a for loop.

for(int i = 0; i < controllers.length; i++) {
        if(controllers[i].getType() == Controller.Type.STICK) {
            window = new JFrameWindow();

    while(true)
    {
1

There are 1 answers

0
0xDEADBEEF On

every while loop have test conditions when it is true it will continue to loop when you don't have a control variable that will stop the application or make the test condition to be false an infinite loop will occur..same with other loop(for loop, do while loop) think of another method so that your while loop will not continue to loop forever so that you can execute your for loop again