error with my if command

"it gives me this error code. i have tried looking it up and and cant find anything.

project_bluetooth:48:2: error: expected unqualified-id before ‘if’

if (state == ‘G’) {

^

exit status 1
expected unqualified-id before ‘if’"

i have no idea what the problem is.
here is my code if that helps.

int red = 12;
int green = 11;
int blue = 10;
int state = 0;
int flag = 0;

void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);

Serial.begin(9600); // Default connection rate for my BT module
}

void loop() {

if(Serial.available() > 0){
state = Serial.read();
flag=0;
}

if (state == ‘W’) {
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}

if (state == ‘P’) {
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}
}
if (state == ‘U’) {
for (float x=0;x < PI; x = x + 0.000004)
red = brightness * abs(sin(x*(180/PI))); // calculate red brightness
green = brightness * abs(sin((x+PI/3)(180/PI))); // calculate green brightness
blue = brightness * abs(sin((x+(2
PI)/3)*(180/PI)));// calculate the blue brightness
analogWrite(red, red); // send the value to the LED
analogWrite(green, green); // send the value to the LED
analogWrite(blue, blue); //
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}
}

if (state == ‘G’) {
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}
}
if (state == ‘R’) {
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}
}
if (state == ‘B’) {
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}
}
if (state == ‘F’) {
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
if(flag == 0){
Serial.println(“LED: on”);
flag = 1;
}
}
}

(deleted)

And that’s not the only mistake:

  • There should be a curly bracket after for (float x=0;x < PI; x = x + 0.000004).
  • Please press Ctrl+T in the IDE to format the sketch and you’ll see that the numer of curly brackets is not even; I see at least 4 more errors.