LinuxN00b LinuxN00b - 16 days ago 6
Java Question

Assign variable in Java while-loop conditional?

I have a method that does a lot of checking and computation and returns a custom class, returnMessage. returnMessage has 2 booleans and a String. What I want to do is run this method in a while loop from my main class and have access to the returnMessage object after the while loop terminates for the last time.

In php this would be a case of

while ( $returned = myObject->myMethod()->finished )
{

}

if( $returned -> finished == FALSE)
{
...
}


However trying to assign like this gives me a boolean expected error in java (there might be php errors in the above, it's late :D )

Answer

We need to see more of your code, but guessing a little I think something like this would work:

ReturnMessage returned;
while (!(returned = myObject.myMethod()).finished) {

}
if (!returned.finished) {

}