Problem with DO...WHILE command - Expected Primary Expression Query

Hi there,
Having a bit of a problem getting my program to compile. It is a simple Ped Xing program but I have tried to use the do...while command to reduce the amount (number of lines) of code needed for a simple operation.

I am getting the fault - expected primary expression before ')' token - when trying to compile the script but cannot find how to assign a value or reference to the "while" command (if that makes sense).

Would really appreciate any help on this as it has both my tutor and myself stuck. The program will be run on breadboard when completed.
The notes within the code are just for myself as I have gone along

/* This program is for a simple traffic light sequence
with a push button and signal for pedestrian crossing */

int ledRed = 12;
int ledYellow = 11;
int ledGreen = 10;
int pedRed = 9;
int pedGreen = 8;
int pushBut = 2;
//These lines set the address on the Arduino board

/*This code states if items on breadboard are input or output*/
void setup(){
  pinMode(ledRed, OUTPUT);
  pinMode(ledYellow, OUTPUT);
  pinMode(ledGreen, OUTPUT);
  pinMode(pedRed, OUTPUT);
  pinMode(pedGreen, OUTPUT);
  pinMode(pushBut, INPUT);
}
void loop(){
  digitalWrite(pedRed, HIGH);
  digitalWrite(ledGreen, HIGH);

  if (digitalRead(pushBut) == HIGH)//Ped button pushed, LED's "DO" sequence "WHILE" lights do another sequence
 do {
   
//This is where I am up to, need to define parameters for DO and While commands
 delay(3000);
 digitalWrite(pedRed, LOW);
    digitalWrite(pedGreen, HIGH); //Could put another delay in after this line to help with timing
delay(1000);
    pulseIn(pedGreen, HIGH, 3000);
 digitalWrite(pedGreen, LOW);
 digitalWrite(pedRed, HIGH);
                              /*Leaving a space here could help make different parts of code clearer */
 } 

 while();
delay(1000);
 digitalWrite(ledGreen, LOW);
 digitalWrite(ledYellow, HIGH);
delay(1000);
 digitalWrite(ledYellow, LOW);
 digitalWrite(ledRed, HIGH);
delay(1000);
 digitalWrite(ledRed,LOW);
    pulseIn(ledYellow, HIGH, 3000);
 digitalWrite(ledYellow, LOW);
 digitalWrite(ledGreen, HIGH);


return;
}

The while part requires a statement that evaluates to true or false, to continue or exit the loop respectively.

for a never ending loop for instance:

do{

}while(true);

Maybe you want to remove the if above the do and use it as the continuation.

do{

}while(digitalRead(pushBut) == HIGH);

Although that will always run once before it checks the button, a simple while checks before starting.

while(digitalRead(pushBut) == HIGH){

}

GreyE30:

while();

I am getting the fault - expected primary expression before ')' token - when trying to compile the script but cannot find how to assign a value or reference to the "while" command (if that makes sense).

Would really appreciate any help on this as it has both my tutor and myself stuck.

Get a different tutor. If your tutor can't figure out what's wrong with that line of code, they are not competent to tutor you on a coding project.

Would this help?

http://arduino.cc/en/Reference/While

Lefty

You know what?
I think this is a perfectly valid question.

Consider:

while () {
  //do something
}

and

for (;;) () {
  //do something
}

Both should be equivalent, if what we're told about the equivalency of "for" and "while" loops.
One compiles, the other doesn't, but only by some odd quirk of convention.

Thanks for the advice, it confirms what I was thinking. So my next question is then, if I make my "while (true)" statement to be whilst pedGreen = HIGH;

Would this then follow for both the "digitalWrite" and "pulseIn" parts of the following code?

Please can you explain further how use of "for" and "while" commands may help the program to run when "do and while" commands do not?

TIA

Both should be equivalent

I don't see that.

while ()
{
//do something
}
and
for (;:wink:
{
//do something
}
are equivalent, but the added () in your example is wrong, as far as I can see.

while {
}

is still syntactically incorrect, but for(;;) is not.
In one example, an empty expression is assumed to be true always, but in the other, it is not.

OP

Please can you explain further how use of "for" and "while" commands may help the program to run when "do and while" commands do not?

A "for" or a "while" loop may never execute the body of the loop, but a "do...while" will always execute the body of the loop at least once.

AWOL:
In one example, an empty expression is assumed to be true always, but in the other, it is not.

My guess is that due to the flexibility of the for loop, the syntax was chosen to allow each of the elements to be optional. This is unusual, and not something that is allowed for boolean expression in general. For example, this doesn't compile:

if()
{
}

Missing out expressions from the for loop is slightly unusual but an experienced programmer should not be surprised to see it.

Leaving out expressions in while, if statements and so on is obviously and glaringly wrong. An experienced programmer seeing that there is an error on that line should immediately realise what is missing, even without the compiler error message pointing to the parenthesis and saying "Hey, you left something out HERE".

the syntax was chosen to allow each of the elements to be optional.

I've got no problem that you can miss out an expression, I was just commenting that a missing expression in one particular case should evaluate to "true" is quirky.

So I have updated my code and it now compiles... The problem now is that it seems to be ignoring my first two digitalWrite commands and is then getting stuck in a indefinite loop between the 2 Ped Led's flashing as per the sequence I stated. None of the other LEDs are coming on and there is no interrupt when I press the push button...

Any clue as to how I can correct my code?

Thanks

  digitalWrite(pedRed, LOW);
  digitalWrite(ledGreen, HIGH);
  
}

void loop(){
  if (digitalRead pushBut == HIGH) > 5000)//Ped button pushed, LED's "DO" sequence "WHILE" lights do another sequence
 
void digitalRead
 do {
   
//This is where I am up to, need to define parameters for DO and While commands
 delay(3000);
 digitalWrite(pedRed, LOW);
    digitalWrite(pedGreen, HIGH); //Could put another delay in after this line to help with timing
delay(1000);
    pulseIn(pedGreen, HIGH, 3000);
 digitalWrite(pedGreen, LOW);
 digitalWrite(pedRed, HIGH);
                              /*Leaving a space here could help make different parts of code clearer */
 }

 while(digitalRead(pushBut == HIGH));
delay(1000);
 digitalWrite(ledGreen, LOW);
 digitalWrite(ledYellow, HIGH);
delay(1000);
 digitalWrite(ledYellow, LOW);
 digitalWrite(ledRed, HIGH);
delay(1000);
 digitalWrite(ledRed,LOW);
    pulseIn(ledYellow, HIGH, 3000);
 digitalWrite(ledYellow, LOW);
 digitalWrite(ledGreen, HIGH);


return;
}

I don't see this compiling:

  if (digitalRead pushBut == HIGH) > 5000)//Ped button pushed, LED's "DO" sequence "WHILE" lights do another sequence
 
void digitalRead

Could you post the whole sketch (that does compile).

How are your switches wired? snippets-r-us.com is down the internet a ways. Here, we get to see ALL of your code, after you make sure it compiles.