设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12552|回复: 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有吧) O5 Z8 P& u' T' h0 y: q
loop
, w( N  l2 E) C0 h( J* y" z% u! Ploop [ commands ]
1 k' Y+ x' \3 Z* m' t/ pRuns the list of commands forever, or until the current procedure exits through use of the stop
' _+ n1 S& W4 gcommand or the report command.
) b; \6 \# e! P  ]+ A- F8 q7 w$ kNote: In most circumstances, you should use a forever button in order to repeat something forever.
5 m- q: L3 t4 _/ X$ OThe advantage of using a forever button is that the user can click the button to stop the loop/ y+ O( J% d  P# o( \3 U1 l- P

% x) X% a" w& j1 ?; k$ z(version 3.1.3)
7 P! [0 r) o7 g" o, e3 E4 m' o7 J不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]9 b. t, y/ `$ T, o" ]9 c/ u
to setup
/ h, r2 `- e" @* `. C8 ]   set p  15 o0 l: s3 `# D8 I; K. W) v7 U
   set p  p + 1
0 T3 d& G0 V9 g' ^: Q# X   show p3 D0 ~; _0 _9 |! E& s& p) O% n
   end3 x6 w5 b4 g. d" p) n
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。' a& e7 ^! G$ k. Q4 w
5 y2 G! K" {) g
[ 本帖最后由 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 ]
! C/ U8 W- {2 ^) g2 D9 P/ v. Rto setup0 _% M% A9 y* j# Y
set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]
% {& V/ Z# }: h5 `set ml filter [ ? = 1] ml
1 h3 e. n* L9 A8 H& S6 h* @set p  1* h. Y% ^5 X2 S0 d( `% o. I* z
repeat length ml [ set p  p + 1]
; C) ^7 d0 b) ~. Y! V+ u6 H5 qif p > 100[stop]; ^+ a8 S/ ^- N  L+ D
show p
( G3 a: X0 e  ]# L0 Y% b' d0 x1 i# aend
' i# h- \9 ^. {$ j5 ?
8 F& {8 s) M5 q6 Y6 [像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?5 N  c, d, ]/ f2 T9 m7 }* x

, x' A% X# J) |) h0 x: [5 R[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
# O: n  @7 N& ?& X9 l5 S) _9 c/ k, Hreduce [ ? 1 + ? 2 ][1 2 3 4]
- F% ^. ]  U5 ^* o相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-8 07:30 , Processed in 0.016428 second(s), 13 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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