0

I'm new to Java, and I want to know if it is possible to break a while loop from an if/for loop inside, for example:

while(true)
{
    for(i=0;i<=10;i++)
    {
        if(i==9) break;
    }
}

This will terminate the for loop(I think?), but how do I terminate the while loop when i reaches 9?

Spano
  • 73
  • 4
  • 1
    First of all, `if(i=9)` will actually SET the value of i to 9. You want `if(i==9)` to do a comparison of i to 9. – D M Jan 22 '17 at 23:09
  • You need a termination condition to allow the `while` loop to exit, maybe a `boolean` value you change instead the `if(i==9)` statement – MadProgrammer Jan 22 '17 at 23:10

0 Answers0