# How to fix " Compilation error: expected primary-expression before '\<=' token " error in my code

**URL:** <https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433>\
**Category:** Programming\
**Created:** [March 20, 2023, 4:12pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433 "2023-03-20T16:12:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkblast](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kkblast/32/935229_2.png) [@kkblast](https://forum.arduino.cc/u/kkblast)\
**Post date:** [March 20, 2023, 4:12pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433/1 "2023-03-20T16:12:33Z")

</div>

Hey everyone, I'm new to coding on Arduino and just can't figure out an error occurring in my code. I am getting an Compilation error: expected primary-expression before '\<=' token

Below is my entire code:

```cpp
#include <Servo.h>

Servo myservo;  

int pos = 0;    

//www.elegoo.com
//2016.12.08
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;

void setup() {
  Serial.begin(9600);
  myservo.attach(9);  
  Serial.begin(9600);
   delay(1000);
}

void loop() {
  a=sr04.Distance();
   Serial.print(a);
   Serial.println("cm");
   delay(1000);
  if (a)<= 40;
  
   for (pos = 0; pos <= 180; pos += 1) { 
    // in steps of 1 degree
    myservo.write(pos);             
    delay(1);                       
  }
  for (pos = 180; pos >= 0; pos -= 1) { 
    myservo.write(pos);             
    delay(1);                       
  }
 
}

```

PLS PLS PLS help!!

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [March 20, 2023, 4:16pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433/2 "2023-03-20T16:16:03Z")

</div>

Welcome to the forum

```cpp
  if (a) <= 40;

```

That is not how you write an if statement in C

Did you perhaps mean

```cpp
  if (a <= 40)

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [March 20, 2023, 4:16pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433/3 "2023-03-20T16:16:57Z")

</div>

It will not cause an error but why

```cpp
  Serial.begin(9600);

```

twice ?

---

<div class="post-metadata">

**Author:** ![kkblast](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kkblast/32/935229_2.png) [@kkblast](https://forum.arduino.cc/u/kkblast)\
**Post date:** [March 20, 2023, 4:18pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433/4 "2023-03-20T16:18:32Z")

</div>

> [@UKHeliBob](#):
>
> ` if (a <= 40)`

Sir, you are a HERO!! ty

---

<div class="post-metadata">

**Author:** ![kkblast](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kkblast/32/935229_2.png) [@kkblast](https://forum.arduino.cc/u/kkblast)\
**Post date:** [March 20, 2023, 4:19pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433/5 "2023-03-20T16:19:12Z")

</div>

noted boss ty

---

<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 16, 2023, 4:19pm UTC](https://forum.arduino.cc/t/how-to-fix-compilation-error-expected-primary-expression-before-token-error-in-my-code/1104433/6 "2023-09-16T16:19:27Z")

</div>

Closed on September 16, 2023, 4:19pm UTC

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