💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Haxe不支持像 C 中传统的 for 循环。它的 for关键字期望一个开口的圆括号 (,然后一个变量标识符,之后一个关键字 in,和一个任意表达式作为迭代的集合;在闭口的圆括号 ) 之后,是任意的循环体表达式。 > Haxe does not support traditional for-loops known from C.Its for keyword expects an opening parenthesis (, then a variable identifier followed by the keyword in and an arbitrary expression used as iterating collection. After the closing parenthesis ) follows an arbitrary loop body expression. ~~~ for (v in e1) e2; ~~~ 类型工具确保 e1 的类型可以被迭代,典型的情况是是否有一个iterator方法返回一个Iterator<T>类型,或者它本身是一个 Iterator<T>类型。 > The typer ensures that the type of e1 can be iterated over, which is typically the case if it has an iterator method returning an Iterator<T>, or if it is an Iterator<T> itself. 变量 v 然后可以在循环体 e2 中使用,保存了e1集合的某个个体元素。 > Variable v is then available within loop body e2 and holds the value of the individual elements of collection e1. Haxe有一个特别的范围操作符控制迭代次数。这是一个二院操作符,操作两个操作数:min...max,返回一个从min(包括)到max(不包括)的IntIterator类型的实例。注意,max不能小于min。 > Haxe has a special range operator to iterate over intervals. It is a binary operator taking two Int operands: min...max returns an IntIterator instance that iterates from min (inclusive) to max (exclusive). Note that max may not be smaller than min. ~~~ for (i in 0...10) trace(i); // 0 to 9 ~~~ for表达式的类型总是 Void ,也就是说没有值可以被使用作为右侧表达式。 > The type of a for expression is always Void, meaning it has no value and cannot be used as right-side expression. 循环的控制流被 break(第5.20节)表达式影响,也受 continue(第5.21节)表达式影响。 > The control flow of loops can be affected by break (5.20) and continue (5.21) expressions.