设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12819|回复: 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有吧4 @; I  w, w) P# T2 {
loop/ S% [6 F) c" V+ Z) y( c
loop [ commands ]& Y6 U  e" t! d! r8 _
Runs the list of commands forever, or until the current procedure exits through use of the stop, q5 K# j+ ^( l: @+ M' A
command or the report command.( D  i. K1 _* G- [  o: K6 t
Note: In most circumstances, you should use a forever button in order to repeat something forever.
1 u& d) }. P" T' o( j& f& Q  nThe advantage of using a forever button is that the user can click the button to stop the loop
+ k5 z5 H7 `' R: C* }. g8 G2 F' _' E( q- A9 Z1 |+ `2 D0 i
(version 3.1.3)
' r) `) \8 a" V5 e8 J- `( f) Z不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]7 v/ B  q0 ~% r
to setup" p8 k0 e6 L; U! q( ?, u
   set p  1
3 `0 X+ B' K% n) v4 {   set p  p + 1: C" u  }* l/ s$ L! T; n) V
   show p
: X; d/ O1 U6 C   end* T2 n) \9 B# k
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。
, S5 `/ }8 a& p4 t' u* V. W
+ \- B" w, H3 i' @$ V* l6 I[ 本帖最后由 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+ R0 G6 J' ~- A
to setup
4 E, Y- h7 d& \% B, [set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]
/ }$ U8 Y, k3 yset ml filter [ ? = 1] ml0 B3 _. B9 s& S$ e- g  G
set p  1! U1 @7 I2 t& S3 i1 x% \, S
repeat length ml [ set p  p + 1]1 U! @3 J/ b. C1 r9 [, A% B
if p > 100[stop]4 L; M4 q( q) C: r3 v- ~6 Z
show p
3 J" r; A! X- Send: `6 Z3 n6 _5 V- S' U

$ x- ?- b( f5 O$ g, p像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?; k% s. D' u0 u$ ]5 @( }2 S
  i3 [3 ?3 e# {# K3 q
[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加
$ X! Y# |- N7 \7 ~" n( |* Ureduce [ ? 1 + ? 2 ][1 2 3 4]
2 @6 t( G4 }5 a1 b! y, h相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-24 02:28 , Processed in 0.017534 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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