设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11516|回复: 7

[求助] 循环

[复制链接]
发表于 2008-4-10 17:04:15 | 显示全部楼层 |阅读模式
5仿真币
关于logo的循环结构程序可使用哪些源语啊?如loop,之类的,basic有很多,但在logo上好像不能使用。
 楼主| 发表于 2008-4-10 17:26:56 | 显示全部楼层

谢谢

我再摸索摸索。
发表于 2008-4-10 17:56:17 | 显示全部楼层
loop有吧
$ h! p, k; C9 S% ^4 i. [) n" A5 P1 Mloop. V) w' u+ g. C9 l2 d6 a5 l+ `
loop [ commands ]) k7 O0 l( H% ], B2 d6 z' b1 q0 H
Runs the list of commands forever, or until the current procedure exits through use of the stop
; s% O# Y2 |, f. pcommand or the report command.
1 [5 c: y: x0 y: a( E: bNote: In most circumstances, you should use a forever button in order to repeat something forever.
' ?4 Q7 [8 k3 a: X9 ]$ QThe advantage of using a forever button is that the user can click the button to stop the loop
1 O  a( |5 K2 A* w( ?3 |$ l) c8 G$ Z, e1 y7 C" |" K/ a* M( g
(version 3.1.3)
5 F% _3 B$ P: r: D不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
3 S4 t: s& ~/ @1 t7 w1 [to setup
2 I( h. J- I- |; i$ c   set p  1. c' e* C  w; T
   set p  p + 1
" d. M* c# h" e0 J& g2 R. Z   show p
( L6 @6 ?0 }( j) W3 D; o1 _, z   end
$ x  |2 D5 q  E" \5 \我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。
2 Q, U7 _3 _2 j
5 N  `% ?5 b% K3 N2 z2 m[ 本帖最后由 wjcpcahu 于 2008-4-11 10:25 编辑 ]
发表于 2008-4-11 10:35:25 | 显示全部楼层
将该procedure与一个forever的button建立联系,同时procedure中加一个if p>100[stop], 不知道楼主说的是不是这个意思
 楼主| 发表于 2008-4-11 10:58:31 | 显示全部楼层

多谢,看来还是要用repeat

globals[p ml ]
' h$ b# C) u, jto setup2 o6 C& e8 c7 F, k) ?& f! a
set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]0 S8 i. E( Q9 M. p! a- Y8 ?4 ~
set ml filter [ ? = 1] ml: v2 c; {3 |7 f. f3 d
set p  10 |% a! |4 \; U+ d% }. t2 g0 ^
repeat length ml [ set p  p + 1]2 ?1 f6 O! s( T) H
if p > 100[stop]" i3 P" \6 C$ e' X2 P+ n
show p 1 H5 _2 V8 F" J
end
$ W0 \* q$ q0 m
* `/ _* Q3 ^! N像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
# Q1 |# C7 _' o2 \6 Z: X
/ Q# l8 Q% H3 _2 K[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
, J3 i! Q( R/ M& _! s. h0 c8 greduce [ ? 1 + ? 2 ][1 2 3 4]
% {2 D- o- j' X! W* ^$ E) V) Y相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-2-10 03:34 , Processed in 0.015588 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表