循环
关于logo的循环结构程序可使用哪些源语啊?如loop,之类的,basic有很多,但在logo上好像不能使用。谢谢
我再摸索摸索。 loop有吧loop
loop [ commands ]
Runs the list of commands forever, or until the current procedure exits through use of the stop
command or the report command.
Note: In most circumstances, you should use a forever button in order to repeat something forever.
The advantage of using a forever button is that the user can click the button to stop the loop
(version 3.1.3)
不过好像不大推荐
补充
globalsto setup
set p1
set pp + 1
show p
end
我想表达的是让这个循环一直下去,直到p=100时才停止,logo语言该怎么写呢?除了repeat,可否用其它原语表示。
[ 本帖最后由 wjcpcahu 于 2008-4-11 10:25 编辑 ] 将该procedure与一个forever的button建立联系,同时procedure中加一个if p>100, 不知道楼主说的是不是这个意思
多谢,看来还是要用repeat
globalsto setup
set ml n-values 200 ]
set ml filter [ ? = 1] ml
set p1
repeat length ml [ set pp + 1]
if p > 100
show p
end
像这种简单的迭代加和还可以,但如果牵涉到多变量的迭代加和,不知道该怎么表达。还有,如果想取出运行中每个阶段的值而不仅仅是终值,该怎么取呢?
[ 本帖最后由 wjcpcahu 于 2008-4-11 11:25 编辑 ]
感激!!
:handshake 什么都不说了,都在程序里了。 reduce也可以做累加reduce [ ? 1 + ? 2 ]
相当于(((1+2)+3)+4)
页:
[1]