设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13386|回复: 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有吧
; ^/ _: `% b. D& w/ ~9 C  @loop- j. F/ S. i8 n! z  J+ L
loop [ commands ]9 g) s) m* T8 m
Runs the list of commands forever, or until the current procedure exits through use of the stop" ^! \( o- k& y% j/ P; Y( U
command or the report command.5 y) Z5 b2 T# `7 e& \
Note: In most circumstances, you should use a forever button in order to repeat something forever.
0 f2 @' t- S# c! F: D' RThe advantage of using a forever button is that the user can click the button to stop the loop4 d7 _% t1 r; K5 z; N

2 C: D. u( K1 V/ ?: m& l. i) |(version 3.1.3)
" @/ Z3 z- x; M( @不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
" d2 a; X' m: _+ T6 hto setup
; m" \$ H/ S" }9 u   set p  1( J9 a/ @! _8 v6 t* o9 E2 y
   set p  p + 1
8 d7 s7 z' `! n$ A& l5 O+ i4 `   show p
  x* A% U, b+ w# T2 @. n+ j   end
3 ]9 K% n3 l6 q! f: I我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。% K& w9 ]0 a! w5 e, b- R
- o9 r5 B6 P9 s# }* \
[ 本帖最后由 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 ]
, f) g8 z+ b) d* F* o* dto setup
' j3 j; s- \! w; aset ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]
3 ]4 D1 ^' E& `# K: d# bset ml filter [ ? = 1] ml  w* C! ~+ w& q
set p  1
: g" A8 y4 s  Q4 L: M1 Brepeat length ml [ set p  p + 1]
: J% F' ?, @' ~5 h" X+ vif p > 100[stop]
8 v6 O+ M3 A2 g/ tshow p ( i. G. E: c9 j1 h4 a' l
end
  p. R( v2 q8 c" g, _2 `; K/ v2 Z& p  ]& p
像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?2 F8 l& A, n! L4 S6 r  R3 a, y
; n" r( Z3 e! }
[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
5 [, {8 l- C8 u3 n" ireduce [ ? 1 + ? 2 ][1 2 3 4]
; e+ O1 d8 |' z/ ^相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-15 16:35 , Processed in 0.016027 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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