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

Phi*_*ter 7 forth gforth

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

如何表示这样的事情的一些具体例子是什么?

while (x > 3) { print(x); x--; }
Run Code Online (Sandbox Code Playgroud)

或者,实际上,只是表达形式的任何具体方式:

while (predicate) { expression(s) }
Run Code Online (Sandbox Code Playgroud)

Lar*_*off 9

您的第一段代码转换为:

\ 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
Run Code Online (Sandbox Code Playgroud)

第二个:

begin predicate while expressions repeat
Run Code Online (Sandbox Code Playgroud)