Expected unqualified id before 'while'

Hello, people!

I writed a code for a timer clock.
But when I try to compile the code it says:
42:3 Expected unqualified id before 'while'
Here is my code:


#include "Servo.h";
#include "GyverEncoder.h";
#include "LiquidCrystal_I2C.h";
Servo ser;
Encoder enc(2,3,4, TYPE2);
LiquidCrystal_I2C lcd(0x27,20,4);
int a;
int b;
int c;
byte sel;
void setup(){
    pinMode(40, OUTPUT);
    ser.attach(8);
    ser.write(90);
    enc.setTickMode(AUTO);
    lcd.init();
    lcd.begin(0x27,20,04);
    lcd.backlight();
    }
void loop(){
    lcd.setCursor(0,0);
    lcd.print("Seconds:");
    while(1==1){
       if(bool(enc.isRight()) && a < 60){
            a++;
            lcd.setCursor(0,9);
            lcd.print(a);
            }
        if(bool(enc.isLeft()) && a > -1){
            a--; 
            lcd.setCursor(0,9);
            lcd.print(a);
            }
        if(bool(enc.isClick()));
        lcd.clear();
        break;
        }
    }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Minutes:");
    while(1==1){
       if(bool(enc.isRight()) && b < 60){    
        b++;     
        lcd.setCursor(0,9);   
        lcd.print(b);
            }
       if(bool(enc.isLeft()) && b > -1){ 
        b--;    
        lcd.setCursor(0,9);
        lcd.print(b);
            }
        if(bool(enc.isClick())){
        lcd.clear();
        break;
        }
    };
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Hours:");
    while(1==1){
        if(bool(enc.isRight()) && c <= 24){
            c++;
            lcd.setCursor(0,9);
            lcd.print(c);
            }
        if(bool(enc.isLeft()) && c > -1){
            c--;
            lcd.setCursor(0,9);
            lcd.print(c);
            }
    }
       while({
     if(bool(enc.isClick()));
        lcd.clear();
        break;
    if (sel==4){
        int time;
        int time_ends;
        int a2 = a;
        int b2 = b;
        int c2 = c;
        time_ends =+ a;
        time_ends =+ b * 60;
        time_ends =+ c * 3600;
        lcd.clear();
        lcd.setCursor(4,1);
        lcd.print(c);
        lcd.setCursor(5,1);
        lcd.print(":");
        lcd.setCursor(6,1);
        lcd.print(b);
        lcd.setCursor(7,1);
        lcd.print(":");
        lcd.setCursor(8,1);
        lcd.print(a);
        for(time;time!=time_ends;time++){
            a2--;
            if(a2 < 0){
                b2--;
                }
            else if(b2<0){
                c2--;
                }
            delay(500);
            ser.write(65);
            delay(500);
            ser.write(115);
                            lcd.setCursor(4,1);
        lcd.print(c2);
        lcd.setCursor(5,1);
        lcd.print(":");
        lcd.setCursor(6,1);
        lcd.print(b2);
        lcd.setCursor(7,1);
        lcd.print(":");
        lcd.setCursor(8,1);
        lcd.print(a2);
            }
        }
        }
        }
}

You have made a mess of the opening and closing braces for the function code block

Auto format teh code in teh IDE and it looks like this

#include "Servo.h";
#include "GyverEncoder.h";
#include "LiquidCrystal_I2C.h";
Servo ser;
Encoder enc(2, 3, 4, TYPE2);
LiquidCrystal_I2C lcd(0x27, 20, 4);
int a;
int b;
int c;
byte sel;
void setup()
{
    pinMode(40, OUTPUT);
    ser.attach(8);
    ser.write(90);
    enc.setTickMode(AUTO);
    lcd.init();
    lcd.begin(0x27, 20, 04);
    lcd.backlight();
}
void loop()
{
    lcd.setCursor(0, 0);
    lcd.print("Seconds:");
    while (1 == 1)
    {
        if (bool(enc.isRight()) && a < 60)
        {
            a++;
            lcd.setCursor(0, 9);
            lcd.print(a);
        }
        if (bool(enc.isLeft()) && a > -1)
        {
            a--;
            lcd.setCursor(0, 9);
            lcd.print(a);
        }
        if (bool(enc.isClick()))
            ;
        lcd.clear();
        break;
    }
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Minutes:");
while (1 == 1)
{
    if (bool(enc.isRight()) && b < 60)
    {
        b++;
        lcd.setCursor(0, 9);
        lcd.print(b);
    }
    if (bool(enc.isLeft()) && b > -1)
    {
        b--;
        lcd.setCursor(0, 9);
        lcd.print(b);
    }
    if (bool(enc.isClick()))
    {
        lcd.clear();
        break;
    }
};
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hours:");
while (1 == 1)
{
    if (bool(enc.isRight()) && c <= 24)
    {
        c++;
        lcd.setCursor(0, 9);
        lcd.print(c);
    }
    if (bool(enc.isLeft()) && c > -1)
    {
        c--;
        lcd.setCursor(0, 9);
        lcd.print(c);
    }
}
       while({
    if (bool(enc.isClick()))
        ;
    lcd.clear();
    break;
    if (sel == 4)
    {
        int time;
        int time_ends;
        int a2 = a;
        int b2 = b;
        int c2 = c;
        time_ends = +a;
        time_ends = +b * 60;
        time_ends = +c * 3600;
        lcd.clear();
        lcd.setCursor(4, 1);
        lcd.print(c);
        lcd.setCursor(5, 1);
        lcd.print(":");
        lcd.setCursor(6, 1);
        lcd.print(b);
        lcd.setCursor(7, 1);
        lcd.print(":");
        lcd.setCursor(8, 1);
        lcd.print(a);
        for (time; time != time_ends; time++)
        {
            a2--;
            if (a2 < 0)
            {
                b2--;
            }
            else if (b2 < 0)
            {
                c2--;
            }
            delay(500);
            ser.write(65);
            delay(500);
            ser.write(115);
            lcd.setCursor(4, 1);
            lcd.print(c2);
            lcd.setCursor(5, 1);
            lcd.print(":");
            lcd.setCursor(6, 1);
            lcd.print(b2);
            lcd.setCursor(7, 1);
            lcd.print(":");
            lcd.setCursor(8, 1);
            lcd.print(a2);
        }
    }
        }
       }
       }

The problem starts with the loop() function which seems to end too soon thus leaving code outside of any function

        lcd.clear();
        break;
    }
}
lcd.clear();
lcd.setCursor(0, 0);

and so on

not too much?

enc.isRight() is already type boolean

better you start from scratch

a is a global variable so initialized with 0 by the compiler

That's quite an unusual place for a semicolon.

Thank you UKHeliBob for the ready code, I'm noob in long codes, so thanks for code! :slight_smile:

@svetlana_gureva
The code, that @UKHeliBob published - is not a "ready code", is your code with only indentation corrected. All your errors are in place and is you who should find and correct it.

while({
[/quote]
is very unusual and probably an error.

while ( 1==1 ) {
needs at least a break; statement inside the block.
That's not always done.
@svetlana_gureva: You probably messed up the code when copying.

is very unusual and probably an error.
[/quote]

Note that is not my code, it is merely copied from the original