Arduino and the while loop problem

Hi,
Scott here from Salem. I am using an Arduino r3. I am using 4 photoresistors as sensors. When they are all below 300, then I power the pololu motor driver.
The following code works well when all 4 sensors are below 300:

 while(leftValue < 300)
       {
         while(rightValue <300)
           {
             while(upValue < 300)
              {
               while(downValue < 300)
                 {

However this code causes the while statement to pop out when only 2 of the sensors are below 300:

while(leftValue && rightValue && upValue && downValue < 300)

am I doing something wrong. It seems the arduino cannot read multiple conditions in a while statement?
Thanks for your help.
Scott

Hello, Scott.

One correct way to do this would be:

void setup()
{
  ...
  if (leftValue < 300 && rightValue < 300 && upValue < 300 && bottomValue < 300)
  {
    // Power motor driver
  }
  else
  {
    // Disable motor driver
  }
}

I recommend getting a good beginner book about C++.

–David

HI David,
Thank you! Now that I look at your code, it makes sense, as I think to myself…“I should have thought of that”… And yes… I’ll get a book on C++. Have a great day!
Scott