Why do you use () on some conditions?

  1. What do you want to achieve? Keep it simple and clear!

So for years(Like 2017 xd). Ive always wondered why you put () in some conditions. Example:

“if (Something == true) then”

  1. What is the issue? Include screenshots / videos if possible!

Isnt that like the same thing as doing “if Something == true then”?. Ive never fully understood why puttin () in some conditions could be neccessary. Does it change anything? or is it just a preference others have. Now dont get me wrong. I know when to use () in functions and stuff XD. I just never understood and still dont why some people put () in if statements.

Havent really been able to search for topics related to this because i dont really know what to search for. Any help would be really cool so i can get this of my chest xd.

The answer is quite simple,

PEMDAS <----

1 Like

What does “Pemdas” mean?


Not quite sure how a math method would be related to this?

1 Like

im sure some programmers do it habitually or because they are traumatized by logical errors and just wanna be sure. The reason is because conditional statements are operations and in lua there is an order of operations like PEMDAS in math. Putting parenthesis is a way for both the code and reader/writer to know what exactly is being checked.

for example: if true and false or true then
can be changed with parenthesis.
if true and (false or true) then → will run
if (true and false) or true then → wont run

8 Likes

Parenthesis, Exponents, Multiply, Divide, Add, Subtract.

1 Like

its a habit for developers (i also use it)

1 Like

pemdas is the order of operations for math. Parenthsis, exponents, multiply, divide, add, subtract.

In any math equation first solve anything inside parenthesis. Then calculate all exponential values. Next multiply and divide. Finally subtract. It works the same way in code. Im sure you know of the logical operators and, or, and not. Those have their own order of operations. I believe not is first.

1 Like

It could also be a habit because some programming languages require it, such as C#.

if x {} errors
if (x) {} doesn’t

6 Likes

youre right, mb i was rushing. :frowning: