The first form is the most correct for almost all cases. I would even ignore the second. It may seem useful, but it’s best to use a more explicit way when you need this semantics.
The second way does not compare perfect equality in texts, it compares only a part of the text ignoring the excess characters of the first, i.e., it compares the amount of characters that the right text of the operator has, he does not look at what comes after that amount in the first text, so in the example below the x
will be ignored and will be considered equal when using the =
.
"Valorx" = "Valor"
"Valor" == "Valor"
"Valorx" != "Valor"
If you turn on the set exact on
there the =
is equal to ==
. But can you guarantee that in every code it is on? Not always the person can. I advise to call, even so do not use that operator.
One of the problems is that it’s easy to get it wrong. It’s usually not what you want.
For other types it does not change in relation to ==
.
What’s more, when assigning a value to the variable always use :=
and not just =
which works, but confuses the allocation operator with the partial comparison operator. For all intents and purposes ignore the =
, whether to assign or to compare, use only :=
and ==
respectively.
This is a syntax defect inherited from dBase.
Documentation.
In xbase dialects use
=
is a trap, as it can be either assignment or comparison (without the if instead of a syntax error will occur the equivalent ofcVar := valor
, and this will go unnoticed depending on the context). As @Maniero said, better:=
or==
. I even set up my editor to show the=
Alone with a red background to avoid danger, I use Harbour a lot in everyday life. (If not known, Harbour would be more or less like ADVPL in syntax, but implemented in a very solid way, for general use and cross-platform, with backward compatibility with Clipper)– Bacco
Thank you, I didn’t even know it was possible to do value assignment like this, I was always taught to do with :=
– Dev80