如何在Gforth中编写while()循环

8
我想在Gforth中编写一个while()循环。不幸的是,唯一的在线教程由于缺乏示例而无用,并且有关计数循环的示例(我不需要的内容)似乎根本不同。你能给出一些具体的示例来代表类似这样的东西吗?
while (x > 3) { print(x); x--; }

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

while (predicate) { expression(s) }
1个回答

11

你的第一段代码翻译为:

\ 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接