while 循环采用以下格式:
while (condition) { statement1; statement2; ... }
while 语句将检查条件。如果条件为 true,则执行块,然后重复。只要条件为 true,块将继续执行。
float $test = 0; while ($test < 5) { print("$test equals: " +$test+"\n"); $test = $test + 1; }
该示例将在“脚本编辑器”(Script Editor)中打印以下行:
$test equals: 0 $test equals: 1 $test equals: 2 $test equals: 3 $test equals: 4
如果写入具有无限循环的脚本(通常在 while 语句中),则只有停止 Maya(例如,从 Windows 的“任务管理器”中),才能中断该循环。