设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11524|回复: 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有吧6 K- b" }: `! {; ~1 h
loop
" Z1 c1 t8 Y. i* K% sloop [ commands ]
. B1 A8 E( E6 ~, S2 d/ LRuns the list of commands forever, or until the current procedure exits through use of the stop
( c! i' {; c0 ~6 mcommand or the report command.# [& u  q( h& m3 v' Q+ s
Note: In most circumstances, you should use a forever button in order to repeat something forever.
5 M+ X  a3 n9 Y* V, hThe advantage of using a forever button is that the user can click the button to stop the loop/ t1 L2 I! w5 H  Y
* Z) R) u" I0 l% ?* M. _
(version 3.1.3)# x3 k! H4 S' n: T. b: y
不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]( v: D/ ?5 N- I$ p, _3 W, A
to setup& A; z' {4 `: L- f
   set p  1
. h) Q" O1 [' V: z6 O   set p  p + 1
, I# p. G' \( z% b$ W3 U5 k- x   show p% l" j" o. {( W2 t8 s- i
   end4 {4 H/ @; m2 ?. U! N8 f
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。
( }, \: {2 J) ?7 a- z$ f! p& ]( g" u( u: V/ b8 k8 N, Q1 K% q
[ 本帖最后由 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 ]* O. G  U1 U; U
to setup' c& e' ~# m' d# r1 ~
set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]
+ N0 e: @/ }( j, ]set ml filter [ ? = 1] ml: H6 D" u$ r8 Q* e& h2 G
set p  18 d0 N% r/ t. T% v
repeat length ml [ set p  p + 1]
7 ^. _& v* K0 Y! E  @if p > 100[stop]
% U; S7 ?' c1 @7 I5 M4 d8 H/ Mshow p 4 }+ ~2 i+ x9 S+ A/ d7 X
end7 g  p- W  b1 W5 I, t8 g
6 N: g. l4 D0 d
像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
3 H" |* Q& _3 W' L1 q1 D8 @% ^& o: f! d% T7 I( w# S+ u' G, K
[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加5 s! c' H2 ?& V
reduce [ ? 1 + ? 2 ][1 2 3 4]8 I* N# i* V+ E( s( M8 a
相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-11 02:10 , Processed in 0.016864 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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