Student question on if statement not working


I am trying to build a “knight rider” type led setup.

I want to increase it’s delay by increments to a certian point and then have it reset to it’s original delay.

As I have it now, it goes quickly in one direction and then slow in the other.

int timer = 100;

void setup(){
for (int ledPin = 2; ledPin <8; ledPin++){ //sets each pin as output and named ledPin
pinMode (ledPin, OUTPUT);
void loop(){
for (int ledPin = 2; ledPin <8; ledPin++){ //loops ledPin from lowest to highest
digitalWrite (ledPin, HIGH); //ledPin ON
digitalWrite(ledPin, LOW); //ledPin OFF
for(int ledPin = 7; ledPin >=2; ledPin–){ //loops ledPin from highest to lowest
digitalWrite(ledPin, HIGH); //ledPin ON
digitalWrite(ledPin, LOW);

timer = timer + 100;
{ if(timer>=700);


The semicolon does not belong at the end of the if statement. The semicolon ends the statement and the next statement is executed unconditionally.

Please read the "how to use the forum" stickies to see how to format and post code.

Thank you for your assistance

You should forget about using delay() in your sketches.
There is an example called Blink Without Delay in the IDE which shows how do timing.

Read Robin2's discussion here: