Using && in a If statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Using && in a If statement

I'm new on programming, in fact I just started learning, and I'm trying to use a condicional "If" but when defining the condition, I want to use the "&&" operator in order to define a lower and an upper límites, but when running the code it gives me an error saying unespected "<=" Is it because we cannot use "&&" when using "If"? If I remmove the "&&" and one of the limits the code runs without error.

20th Jun 2020, 2:41 AM
César Aguilar
César Aguilar - avatar
5 Answers
+ 2
Please provide the code, your description is not very clear.
20th Jun 2020, 2:59 AM
Sandra Meyer
Sandra Meyer - avatar
+ 2
Thanks, now I can see the bug 😉👍 You have to repeat the variable name for each sub-condition, like this: if a > 0 && a <= 10
20th Jun 2020, 3:15 AM
Sandra Meyer
Sandra Meyer - avatar
20th Jun 2020, 3:10 AM
César Aguilar
César Aguilar - avatar
+ 1
It something like that, gives me a unnexpected "<=" error or something like that. I cant figure out wahts wrong
20th Jun 2020, 3:11 AM
César Aguilar
César Aguilar - avatar
+ 1
What a silly mistake I made, lol thank you so much, my Head was a out to explode
20th Jun 2020, 3:19 AM
César Aguilar
César Aguilar - avatar