The mathematical "not" integer

Why does delphi do the mathematical “not” of an integer rather than the force to cast to a boolean value during a loop? Example

var myint:integer;
...
myint:=1;  
while not myint=5 do
begin
  myint:=myint+1;
  showmessage('myint now is : '+inttostr(myint));
end;    
+4
source share
2 answers

Your statement uses two operators: notand =. To understand how it is analyzed, you need to familiarize yourself with the operator's priority table .

Operators precedence
----------------------------
@ first (highest)
not
----------------------------
* second
/
div
mod
and
shl
shr
as
----------------------------
+ third
-
or
xor
----------------------------
= fourth (lowest)
<>
<
>
<=
> =
in
is
----------------------------

, not , =. , :

(not myint) = 5

, , not .

, , , not:

not (myint = 5)

(myint = 5) , not .

, , . , , .

, , <>:

myint <> 5
+11

, Delphi , , not , . , . , , = (, , ).

delphi , , :

if not (myint = 5) then....
// vs
if (not myint) = 5 then
// vs
if not myint = 5 then

, .

BTW: ( ) 3+4*5. , * +.

+8

Source: https://habr.com/ru/post/1530919/


All Articles