Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共14 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:怎么改成循环语句??

1楼
弦外之音 发表于:2011/8/3 1:52:54

  怎么把以下代码写成循环语句?

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;

2楼
26327756l 发表于:2011/8/3 9:07:46

使用数组

仅供参考

 

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

3楼
弦外之音 发表于:2011/8/3 9:49:11
以下是引用26327756l在2011-8-3 9:07:46的发言:

使用数组

仅供参考

 

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

def14 , def13 , def12  不是某个计算公式,而是分别用来定义某个条件下的价格,跟 def[14] ,def[13] , def[12] 不一样,怎么用数组??
4楼
26327756l 发表于:2011/8/3 10:04:37

VARIABLE:def[14]=0,xyz[14]=0;

def[] 和xyz[] 可以存放不同价格

你要分开赋值,就好比

def[1]:=1231;

def[2]:=34343;

def[3]:=54545;

……

5楼
弦外之音 发表于:2011/8/3 10:19:03
以下是引用26327756l在2011-8-3 10:04:37的发言:

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没有触发到。这个在数组中有体现吗??

6楼
fly 发表于:2011/8/3 10:21:13

ELSE IF的属于分支结构,如何能划到循环里去.

逻辑上就说不过去

7楼
jinzhe 发表于:2011/8/3 10:24:51
你要那样改就不能是循环了
8楼
弦外之音 发表于:2011/8/3 10:29:05
那应该怎么改?原始代码的运算很慢,每次加载都要缓冲好几秒,怎么让它运算快一些呢??
9楼
26327756l 发表于:2011/8/3 10:35:23

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 的逻辑 ,细节上有点出入,你的具体的情况不明,只写思路,仅供参考。

10楼
弦外之音 发表于:2011/8/3 10:46:22
以下是引用26327756l在2011-8-3 10:35:23的发言:

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。

 

共14 条记录, 每页显示 10 条, 页签: [1] [2]


Powered By Dvbbs Version 8.3.0
Processed in 0.06250 s, 3 queries.