设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11776|回复: 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有吧
; b8 V: y2 i; s+ Iloop
( }- t5 R6 n* m( F$ q+ \& ?& Xloop [ commands ]
' s, \/ M- I- i  k, \0 D: X3 lRuns the list of commands forever, or until the current procedure exits through use of the stop
/ V/ N/ i0 B5 }( Pcommand or the report command.8 y! s/ A. c4 y
Note: In most circumstances, you should use a forever button in order to repeat something forever.( [4 Q: Y8 @7 ~3 x
The advantage of using a forever button is that the user can click the button to stop the loop. C: @' H% T4 ^8 Y; r$ q- q

& m; |: V) c' n/ M* a  C(version 3.1.3). s' [3 c: f8 C5 j9 Y6 i
不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
0 V4 ]- w8 l- w# |9 S$ d0 Lto setup- c" E! V+ j3 U2 h
   set p  1& g7 H1 k; K# P2 u; e* x
   set p  p + 1: z% j  M* r2 a& B6 @  s! x
   show p1 j2 K& R* z. \( ^6 Q9 J/ {
   end, `1 @! z/ v- v7 G1 T) k. c6 g" K
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。6 Z9 H! j# f2 U7 }4 o
- d; ?' h) m2 X7 G# L0 C" 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 ]; y! m: ?. S1 Q/ q5 \
to setup: n/ O( Q# d5 w. I/ n: m
set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]
% c: y! E# y" R5 z* U# S9 f6 Zset ml filter [ ? = 1] ml
- b1 Q5 Y% R2 `5 v1 U, p& l' Q( o- Rset p  1
2 I& b% X$ J7 D: r; C4 f. Yrepeat length ml [ set p  p + 1]9 y* I, g6 A( m2 s" l6 q' [- [
if p > 100[stop]- z4 w% n& m0 T. k. {
show p
% G" Y& {5 K' L, T7 rend% M$ f! a* t/ ]
, y) J. R, }7 f9 o. x7 D
像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
2 K" }* B* Z# D; ?+ Q7 P7 ~; z4 `
[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加# `6 [/ W" N; q+ y. e
reduce [ ? 1 + ? 2 ][1 2 3 4]
) V: n3 s$ x/ w. N9 h相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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