CoffeeScript 中是否遗漏了 `do...while` 循环...? [英] Were `do...while` loops left out of CoffeeScript...?

查看:21
本文介绍了CoffeeScript 中是否遗漏了 `do...while` 循环...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 CoffeeScript 中,while 循环是标准的:

In CoffeeScript, the while loop comes standard:

while x()
   y()

但是,以下1 不起作用:

However, the following1 doesn't work:

do
  y()
while x()

这只是第一个例子的糖:

And this is simply sugar for the first example:

y() while x()

CoffeeScript 是否带有至少执行一次的内置循环?

Does CoffeeScript come with a built-in loop that executes at least once?

1顺便说一句,do 关键字——它用于调用匿名函数.

1As an aside, do is a keyword — it's used to call anonymous functions.

推荐答案

CoffeeScript 文档说:

The CoffeeScript documentation says:

CoffeeScript 提供的唯一低级循环是 while 循环.

The only low-level loop that CoffeeScript provides is the while loop.

我不知道至少执行一次的内置循环,所以我想替代方案是

I don't know of a built-in loop that executes at least once, so I guess the alternative is

loop
  y()
  break if x()

这篇关于CoffeeScript 中是否遗漏了 `do...while` 循环...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆