循环的最常见用途是循环访问数组的每个元素。MEL 采用循环的特殊形式,支持您轻松执行循环。
for-in 循环的形式如下所示:
for (array-element in array) {statement;statement;...}
string $carType[3] = {"Porsche", "Ferrari", "BMW"};string $car;for ($car in $carType) {print("I want a new ");print($car + ".");}
它将在“脚本编辑器”(Script Editor)中打印以下行:
I want a new Porsche.I want a new Ferrari.I want a new BMW.
该循环将执行三次,分别为 $carType 中的每个数组元素执行一次。
,