怎么把以下代码写成循环语句?
if abc>13 then
sss:=def14;
else if abc>12 then
sss:=def13;
else if abc>11 then
sss:=def12;
else if abc>10 then
sss:=def11;
else if abc>9 then
sss:=def10;
else if abc>8 then
sss:=def9;
else if abc>7 then
sss:=def8;
else if abc>6 then
sss:=def7;
else if abc>5 then
sss:=def6;
else if abc>4 then
sss:=def5;
else if abc>3 then
sss:=def4;
else if abc>2 then
sss:=def3;
else if abc>1 then
sss:=def2;
if abc<-13 then
sss:=xyz14;
else if abc<-12 then
sss:=xyz13;
else if abc<-11 then
sss:=xyz12;
else if abc<-10 then
sss:=xyz11;
else if abc<-9 then
sss:=xyz10 ;
else if abc<-8 then
sss:=xyz9;
else if abc<-7 then
sss:=xyz8;
else if abc<-6 then
sss:=xyz7 ;
else if abc<-5 then
sss:=xyz6;
else if abc<-4 then
sss:=xyz5;
else if abc<-3 then
sss:=xyz4;
else if abc<-2 then
sss:=xyz3;
else if abc<-1 then
sss:=xyz2;
使用数组
仅供参考
VARIABLE:def[14]=0,xyz[14]=0;
for i=13 to 1 do
begin
if abc>i then sss:=def[i+1];
if abc<-i then sss:=xyz[i+1];
end
使用数组
仅供参考
VARIABLE:def[14]=0,xyz[14]=0;
for i=13 to 1 do
begin
if abc>i then sss:=def[i+1];
if abc<-i then sss:=xyz[i+1];
end
VARIABLE:def[14]=0,xyz[14]=0;
def[] 和xyz[] 可以存放不同价格
你要分开赋值,就好比
def[1]:=1231;
def[2]:=34343;
def[3]:=54545;
……
VARIABLE:def[14]=0,xyz[14]=0;
def[] 和xyz[] 可以存放不同价格
你要分开赋值,就好比
def[1]:=1231;
def[2]:=34343;
def[3]:=54545;
……
if abc>13 then
sss:=def14;
else if abc>12 then
sss:=def13;
上面用的是else if ,else if abc>12 的前提是条件abc>13没有触发到。这个在数组中有体现吗??
ELSE IF的属于分支结构,如何能划到循环里去.
逻辑上就说不过去
VARIABLE:def[14]=0,xyz[14]=0;
for i=13 to 1 do
begin
if abc<i+1 and abc>i then sss:=def[i+1];
if abc>-i-1 and abc<-i then sss:=xyz[i+1]
end
这样设计 符合elseif 的逻辑 ,细节上有点出入,你的具体的情况不明,只写思路,仅供参考。
VARIABLE:def[14]=0,xyz[14]=0;
for i=13 to 1 do
begin
if abc<i+1 and abc>i then sss:=def[i+1];
if abc>-i-1 and abc<-i then sss:=xyz[i+1]
end
这样设计 符合elseif 的逻辑 ,细节上有点出入,你的具体的情况不明,只写思路,仅供参考。
abc<i+1 and abc>i 的结果只能是abc不存在
if abc>13 then
sss:=def14;
else if abc>12 then //-------------abc=13
sss:=def13;
else if abc>11 then //-------------abc=12
sss:=def12;
else if abc>10 then //-------------abc=11
sss:=def11;
上述代码所要表达的意思是,从abc=2开始一直到abc=14,取最后一个满足条件的abc,得到最后一个满足条件的abc时的sss。