Why does this show me an error bad for loop on my pi 4 (begginer, first timer with normal c)

Viewed 54
#include <wiringPi.h>
#include <stdio.h>
#define ledPin 0

main()
{
    wiringPiSetup()
    int x;
    for(x=0; x<4; x+1)
    {
        digitalWrite(ledPin, HIGH);
        delay(500);
        digitalWrite(ledPin, LOW);
        delay(500);
    }
}    

the error is on line 7 and i've been stuck on it for 2 days (i code in geany)

2 Answers
  1. It sounds like you're getting a compile error on line 8:

    wiringPiSetup()  /* <-- You need to end the line with ";" */
    
  2. Your loop should look like this:

    for(x=0; x<4; x++) {...} /* "x+1" doesn't change the value of "x", so the loop will never terminate */
    

The problem is in your for loop.

for(x=0; x<4; x+1)

The third parameter in brackets does not do anything. You probably wanted to increment x and you will do that with x++ or x+=1.

x+1 will return the value, but that will not be stored anywhere.

Related