从书上看见如下代码,对then nowtag:=nowtag and (buf[i]=$E)
这种用法感到困惑,then后面语句接and是什么意思?请高手解答一下
var
buf array of byte
nowtag :boolean
begin
nowtag:=true;
for i:=0 to 20 do
begin
if ((i mod 2)=0 ) then nowtag:=nowtag and (buf[i]=$E)
else nowtag:=nowtag and (buf[i]=$A);
if not nowtag then break;
end;
end;
这种用法感到困惑,then后面语句接and是什么意思?请高手解答一下
var
buf array of byte
nowtag :boolean
begin
nowtag:=true;
for i:=0 to 20 do
begin
if ((i mod 2)=0 ) then nowtag:=nowtag and (buf[i]=$E)
else nowtag:=nowtag and (buf[i]=$A);
if not nowtag then break;
end;
end;
if nowtag and (buf[i]=$A) then nowtag:=true
else nowtag:=false;
nowtag:=nowtag and (buf[i]=$E)
else
nowtag:=nowtag and (buf[i]=$A);if not nowtag then break;--------------------------------------
nowtag:=nowtag and (buf[i]=$E)
是逻辑运算
因为 nowtag 是 Boolean 类型。(buf[i]=$E)
判断 buf[i] 是否等于 $E , 它返回 True 或 False
然后再与 nowtag and,就又得到一个 Boolean,
最后赋值给 nowtag。