设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11317|回复: 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有吧- Q5 {4 R5 c9 |. u, y
loop
2 ~- I( a, ~* cloop [ commands ]- y4 {# [' D" D' F1 \( H* O) a
Runs the list of commands forever, or until the current procedure exits through use of the stop
4 c  G! S& a2 x1 t# [command or the report command.  s2 s( J9 a" H/ Q& K
Note: In most circumstances, you should use a forever button in order to repeat something forever.
- s' O# k$ T% `7 hThe advantage of using a forever button is that the user can click the button to stop the loop2 m6 Y4 n# s6 k- T/ a, n3 d

0 ]( ]* R) r: X(version 3.1.3)* J8 P1 ^' B$ }: Z9 Q4 Z
不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
2 {( O, R/ F3 I# {7 Jto setup8 ~9 X; A2 w7 u1 Q5 h( @$ G6 q
   set p  1
6 Y% d; I& S: X; K1 y4 o4 o   set p  p + 1
- W* |9 m& ~3 ~# m   show p( z, c* Z( N7 a. |; [
   end
0 ?6 s7 c- _$ r) T我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。1 ~" ?, h$ V3 u* O: |5 ~4 @. ?5 u9 V

- z) f6 ^: G& T% C& ^; 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 ]( n- f9 F0 l" Z. Y* m, I- i
to setup2 n; ^& a2 I6 q+ N
set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]
5 @+ V) c0 G* F, H. @7 p7 \* Y& jset ml filter [ ? = 1] ml. i+ G1 h' `% h, Z% P% p. X
set p  10 w) M) [7 E" G1 x: F7 H- Y
repeat length ml [ set p  p + 1]3 M5 ~- A  r! S, Z: {
if p > 100[stop]
/ G# K: a* L; a, b1 V& i) [- Z% Nshow p
5 S9 i  G7 H. [( \1 ^1 Dend
4 ~  j& i- N* Y7 _. e/ Q$ n3 J& c! o0 n0 T6 l0 i
像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
& b- ?! ?* v# L
* d; h: g7 o, s$ W5 m9 y[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
; O! b/ U8 p; Zreduce [ ? 1 + ? 2 ][1 2 3 4]' W) J8 Z  t3 y6 e7 n9 U' x5 t
相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-10 02:06 , Processed in 0.016663 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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