设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10746|回复: 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 Q: P2 G1 {8 floop0 m: W% w2 [* J5 T( b
loop [ commands ]
% U: i, S9 X* B6 nRuns the list of commands forever, or until the current procedure exits through use of the stop
" l  c4 D( z" d7 ~/ l/ F* ^8 Icommand or the report command.
0 q0 r! w! T& _Note: In most circumstances, you should use a forever button in order to repeat something forever.
- E3 m3 U) t- U& ]  a% YThe advantage of using a forever button is that the user can click the button to stop the loop
3 @: z0 S' f8 o: B5 A* p, `- }! K' O% j8 t
(version 3.1.3)
- Q4 E9 n; J+ |4 d: w不过好像不大推荐
 楼主| 发表于 2008-4-10 23:51:54 | 显示全部楼层

补充

globals[p ]
! p$ Q" j1 i+ Oto setup
+ q7 i4 j2 P% o% F7 d   set p  1. b2 g* m( M" n1 M
   set p  p + 1
$ G& j1 y# J" S, X0 _% P. W+ ?5 [   show p: J4 @# Q( p* F
   end
% U$ |3 q1 Y1 `- k" G: T1 e我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。
7 d& R: f9 v0 ^6 a# {4 p
! I) Y% l: M% N" ?& f6 T[ 本帖最后由 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 ]
) n9 i' m- a1 N, p: Y- t$ Z# Eto setup
9 ?3 \' c5 Z/ \set ml n-values 200 [ifelse-value (random-float 1 < 0.3 ) [0] [1] ]4 l$ Y- ]5 R4 ^' u: B# P
set ml filter [ ? = 1] ml, e8 D3 O' H5 r9 S1 k! _
set p  1$ V5 P+ H8 s2 r8 ^: q- O
repeat length ml [ set p  p + 1]
; ~0 T- w. ^7 L+ ^if p > 100[stop]0 g) [' \- D1 E% M7 J# ^
show p
- C6 q: }- j6 m2 uend& r( W# W* D5 b2 V, l* w

/ Q3 F( b0 N$ |# k! p像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
# j3 n- I& X+ [- e8 t7 z
9 p# \  p/ s/ T2 K- d  m& `7 A[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
 楼主| 发表于 2008-4-11 13:37:42 | 显示全部楼层

感激!!

什么都不说了,都在程序里了。
发表于 2008-4-11 15:21:00 | 显示全部楼层
reduce也可以做累加1 N  d# f5 W2 Y! d
reduce [ ? 1 + ? 2 ][1 2 3 4]
. ]3 P; G; {# f- C# S相当于(((1+2)+3)+4)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-30 11:14 , Processed in 0.016606 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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