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.
Asked: 2023-07-16 07:57:20 +0000
Seen: 9 times
Last updated: Jul 16 '23