Why do we use two equals marks to compare equalities?


#1

soo why do we use 2 equal marks when we are comparing the equalities. i mean… here, take this picture itll be easier…


#2

Thats like asking why they use class instead of anything else or why does English use letters. Its just how they made it(I think. If there is any special reason please explain anyone), Don’t take my word for this tough.


#3

Not all programming languages use == as the equality operator, in much the same way that not all languages use = as an assignment operator.

For example, in Python you can do this:

my_number = 42
if my_number % 3 == 1:
  print("Some random text...")

However, if we were working with Delphi…

var my_number : Integer;

begin
  my_number := 42;
  if my_number mod 3 = 1 then ShowMessage('Some random message!');
end;

Typically, if a language has already used = as an assignment operator then it could make for code that’s very difficult to read if that’s also an equality operator. (Though, I wouldn’t be surprised if there’s a language where that’s the case.)

The use of == to compare equality isn’t universal, just a convention chosen by some languages.

(Also, fair warning: I’m pretty sure the Delphi is correct, but mainly I wanted to demonstrate the difference between it and Python when it came to operators…)