Here's how I would do a while loop:
boolean more = true; while (more) { // do something if (someTest()) { more = false; } }
This is pretty standard. I am curious to know if there is a way to do something similar to the code below in Java: (I think I saw something like this in C)
I only ask about it because at the moment I donβt like how I define the variable used in the condition (in this case: βmoreβ) outside the scope of the loop, although it only matters inside the loop, There is no point in it remained hanging after the cycle ended.
* * Update * *
An idea came to me after visiting the secret secret of Porcaline:
for (boolean more=true; more; more=someTest()) {
This is not perfect; It abuses the for loop, and I cannot think of a way to execute the loop at least once, but it is close ... Is there a way to make sure that the loop runs 1 time?
source share