Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

In Java, to terminate a while loop in the terminal, you can use the break statement. When the break statement is executed within the while loop, it immediately exits the loop, and the program control moves to the next statement after the loop.

For example:

while (condition) {
   // some code here

   if (exitCondition) {
       break; // terminate the while loop
   }

   // more code here
}

In the above code, when exitCondition becomes true, the break statement is executed, and the loop execution terminates.