设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12815|回复: 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有吧& ]" N4 [3 a. V$ r
loop
6 e! v9 P' i" a% oloop [ commands ]# m# M- [2 B% E- k  p- B6 Y
Runs the list of commands forever, or until the current procedure exits through use of the stop, |1 j! T+ R! D# W8 _2 M, G! o/ k
command or the report command.
7 E5 _5 S0 T0 W! y! k9 O# ^! ~Note: In most circumstances, you should use a forever button in order to repeat something forever.
# b( }( ~6 d2 A8 `6 W9 CThe advantage of using a forever button is that the user can click the button to stop the loop4 V% y0 }$ p4 u* F+ ?. h6 ]

: l) a1 G3 d; a" l1 q3 B(version 3.1.3)
& V9 g3 F( z. \) K" u# L: J不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
) J2 [% n' u4 g& x; j& C+ Z5 Yto setup6 u0 a7 \7 |; x7 ^  c
   set p  1* v( \% s3 u' K5 z6 O
   set p  p + 1
0 ]- @5 ]# s* _/ _! l! r   show p' N5 a! y' ~" {& l
   end5 R3 ?( \" j% ?2 a! h2 T7 j
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。
. s  r0 v! a7 q: \+ ]4 K  o( B4 `  \8 A# E, v8 X
[ 本帖最后由 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 ]$ N3 q$ y6 p" D3 v' q" k& T
to setup: X) C1 i; D, h& {
set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]: A: t1 C7 g+ h# X5 J$ Y2 s
set ml filter [ ? = 1] ml
2 y- H0 L: w) K0 P9 t! z6 Xset p  1" S/ S2 G6 a4 Z4 S) o6 Y
repeat length ml [ set p  p + 1]
; A8 z0 E9 k% tif p > 100[stop]4 h) ?+ y3 u, m6 R; c, Y
show p
! j( k2 k  @3 Y9 U) c8 C7 {end
2 U2 j+ H  j9 E- b9 o8 [5 b. k, q: J7 H
像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
3 }/ I- j- E) S7 u6 L
; K8 T6 m& I" n- \1 c% K[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
- ~* L4 F' F( ^0 E# sreduce [ ? 1 + ? 2 ][1 2 3 4]
! ^$ H. ?5 A  ], J/ m相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-23 03:34 , Processed in 0.014641 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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