7

我想在Gforth中写一个 while() 循环。不幸的是,由于缺少示例,在线唯一的教程没有用,并且计数循环的示例(我不是在寻找)看起来根本不同。

如何表示这样的东西有哪些具体的例子?

while (x > 3) { print(x); x--; }

或者真的,只是一些具体的方式来表示任何形式:

while (predicate) { expression(s) }
4

1 回答 1

10

您的第一段代码转换为:

\ Assuming x is on the top of the stack.
begin dup 3 > while dup . 1- repeat

\ Or if x is in memory.
begin x @ 3 > while x ? -1 x +! repeat

第二个:

begin predicate while expressions repeat
于 2015-03-05T16:05:44.117 回答