# Problem : expected unqualified-id before 'if'

**URL:** <https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808>\
**Category:** Programming\
**Created:** [March 21, 2023, 2:41pm UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808 "2023-03-21T14:41:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![geochat](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geochat/32/925971_2.png) [@geochat](https://forum.arduino.cc/u/geochat)\
**Post date:** [March 21, 2023, 2:41pm UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/1 "2023-03-21T14:41:29Z")

</div>

Hi Guys.............. I am having a problem which shows like error: expected unqualified-id before 'if'. here is my code :

int LED1 = 2;  
int LED2 = 3;  
int LED3 = 4;  
int LED4 = 5;  
int LED5 = 6;  
int LED6 = 7;  
int LED7 = 8;  
int LED10 = 11;  
int LED11 = 12;  
const int trigPin = 9;  
const int echoPin = 10;  
int t = 70;

if (distance = 5cm or \> 5cm) { ................................................................//here the code gets error

digitalWrite(led1, HIGH);  
delay(t);  
digitalWrite(led2, HIGH);  
delay(t);  
digitalWrite(led3, HIGH);  
delay(t);  
digitalWrite(led4, HIGH);  
delay(t);  
digitalWrite(led5, HIGH);  
delay(t);  
digitalWrite(led6, HIGH);  
delay(t);  
digitalWrite(led7, HIGH);  
delay(t);  
digitalWrite(led10, HIGH);  
delay(t);  
digitalWrite(led11, HIGH);  
delay(t);  
digitalWrite(led12, HIGH);  
delay(t);  
digitalWrite(led13, HIGH);  
delay(t);  
}  
`//single line`

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [March 21, 2023, 2:50pm UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/2 "2023-03-21T14:50:54Z")

</div>

> [@geochat](#):
>
> if (distance = 5cm or \> 5cm) {

Well, it should be "==", and what is the "cm" doing in there?

```arduino
if (distance == 5 or distance > 5)
// Or simply
if (distance >= 5)

```

Also, which function is that code part of?

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [March 21, 2023, 2:52pm UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/3 "2023-03-21T14:52:27Z")

</div>

Hi, @geochat  
Welcome to the forum.

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

> [@geochat](#):
>
> if (distance = 5cm or \> 5cm) {

This might help with logical operators, OR and AND etc.  
[https://www.circuitbasics.com/using-logical-operators-in-arduino-programming/](https://www.circuitbasics.com/using-logical-operators-in-arduino-programming/)

Tom.. 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![sumguy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sumguy/32/1134826_2.png) [@sumguy](https://forum.arduino.cc/u/sumguy)\
**Post date:** [March 21, 2023, 3:05pm UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/4 "2023-03-21T15:05:23Z")

</div>

Variable names can not start with a number.  
Was this your intention?

```cpp
int cm = 5;
if(distance >=cm){}

```

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [March 21, 2023, 3:09pm UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/5 "2023-03-21T15:09:06Z")

</div>

> [@sumguy](#):
>
> Was this your intention?

The intention is kinda moot - the code isn't in a function.

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [March 22, 2023, 6:23am UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/6 "2023-03-22T06:23:59Z")

</div>

Your topic has been moved to a more suitable location on the forum.

Please edit your post, select all code and click the \</\> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [March 22, 2023, 7:52am UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/7 "2023-03-22T07:52:25Z")

</div>

Hi, @geochat  
Your code is not even Arduino structured;  
This may be of help;

> **[Arduino - Code Structure | Arduino Tutorial](https://arduinogetstarted.com/tutorials/arduino-code-structure)**
>
> Learn: how to program Arduino step by step. The detail instruction, code, wiring diagram, video tutorial, line-by-line code explanation are provided to help you quickly get started with Arduino. Find this and other Arduino tutorials on...

Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 18, 2023, 7:52am UTC](https://forum.arduino.cc/t/problem-expected-unqualified-id-before-if/1104808/8 "2023-09-18T07:52:41Z")

</div>

Closed on September 18, 2023, 7:52am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
