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

How to write a while() loop in Gforth

我想在 Gforth. Unfortunately, the only tutorial online 中编写一个 while() 循环,但由于缺少示例而没有用,而且计数循环的示例(我不想要的)看起来根本不同.

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

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

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

while (predicate) { expression(s) }

您的第一段代码转换为:

\ 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