设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11777|回复: 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有吧5 B: z6 x6 b( K% [$ n: u" D
loop
; R, P+ v! U2 M, L$ x' N, s! Sloop [ commands ]
4 X7 Y& ?9 n! r: f  u2 V" D. [Runs the list of commands forever, or until the current procedure exits through use of the stop
& e( [& C6 ~0 }% @5 |command or the report command.
, J: \0 `& {' H  fNote: In most circumstances, you should use a forever button in order to repeat something forever.
. K/ G1 f; [1 O5 u1 u0 g" \- OThe advantage of using a forever button is that the user can click the button to stop the loop
9 w3 A5 R- s3 }
; y& E+ C5 ]: j- S(version 3.1.3), I$ s. m3 h+ x! X* }/ g1 }( S  }
不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
1 y3 @; A# o0 X/ f- m  pto setup
% l' D3 D! u# p; F& U1 Y+ c0 h   set p  14 @% b  ~; H6 w, _
   set p  p + 1
. x. o1 p: i& r9 E; j8 r9 F- o* |# v1 u   show p
! g% J/ \# L$ w8 R5 Z) R7 ?6 u/ P   end8 d$ b$ c* H& _( T! p! Z
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。# ^! K' w/ M) I- N9 O
# y( E+ I8 K% s7 [* D' [+ M8 K
[ 本帖最后由 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 ]
7 `4 s- }: p8 C& P7 Y9 Lto setup
& Y0 l% A4 w! y) Z" Mset ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]3 `3 \1 c5 `6 F5 V2 V
set ml filter [ ? = 1] ml! ^) f  r) P& y$ t
set p  18 w7 C* @! h! i1 }
repeat length ml [ set p  p + 1]: Q* c; m- u5 P  Z$ Z+ ~; m  l" P0 U
if p > 100[stop]
+ x7 r  k) ]  f# K/ dshow p ' r2 u$ y1 N" Z
end3 [" _# w$ q1 p8 W2 t! v1 ~

) H& Z9 t- |% S像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
7 W! _# D7 \6 X+ w
, d0 O; `8 e' G4 _! j[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
! r5 T2 c7 v, ~& c, Dreduce [ ? 1 + ? 2 ][1 2 3 4]
' C; M4 q, W2 y9 R相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 19:31 , Processed in 0.016545 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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