LinuxN00b LinuxN00b - 1 year ago 104
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 Source

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) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download