Hey guys,

I'm trying to conver a while loop from C++ to java. And I'm having a problem with my while loop.

The original c++ code.

    // Out of cashiers?
    // Get next frontBusyCashierQ
    // Is cashier's finish time now?
    while(!service->emptyBusyCashierQ()                    
          && (service->frontBusyCashierQ(cashier),          
          cashier->getEndBusyTime() <= currentTime)) {
       ......
       ....
       ...
    }

My fail attempt.

  while(!service.emptyBusyCashierQ()
        && (service.frontBusyCashierQ(),
        cashier.getEndBusyTime() <= currentTime))
   {
       ....
       ..
       .
   }

The error is in line 3. Is the comma a problem inside the while loop?

Greatly appreciate any input in advance.

Edited 4 Years Ago by ITOzann

Does the code give a compiler error? Please post it.

What is the , in the middle of the boolean expression for?

Does the code give a compiler error? Please post it.

    CAS.java:248: ')' expected
                  && (service.frontBusyCashierQ()),
                                                  ^
    CAS.java:249: not a statement
                  cashier.getEndBusyIntervalTime() <= currentTime))
                                                   ^
    CAS.java:249: ';' expected
                   cashier.getEndBusyTime() <= currentTime))
                                                          ^
    3 errors

What is the , in the middle of the boolean express

In C++, it is allowed to put a comma in a while loop so you can separate statements that will be evaluated in some order. If I'm not mistaken it, is a sequence point and guarantees order of execution from left to right.

Edited 4 Years Ago by ITOzann

What is the purpose of the comma in a boolean expression? It does not make a valid boolean expression.

This article has been dead for over six months. Start a new discussion instead.