Do while/ja
< Do while
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
LSL ポータル | 関数 | イベント | 型 | 演算子 | 定数 | 実行制御 | スクリプトライブラリ | カテゴリ別スクリプトライブラリ | チュートリアル |
do loop while (condition);
• | loop | – | 一度実行すると、conditionの間実行します。 | |
• | condition | – | もしconditionを実行してtrueなら、再び舞い戻って繰り返しloopを実行します。 |
いくつかのステートメントは空にできます。do...while loop はわずかにwhileもしくはfor loopより速く、while もしくは for loop よりも少ないバイト数でできます(しかし、スクリプトがmonoでコンパイルされた場合には、この実行速度とバイト数の違いはありません)
詳細
例
//1 から 5 までカウント
default
{
state_entry()
{
integer olf; // Without applied value an integer will be defaulted to zero.
do
llSay(0, (string) (++olf)); // Increment before the while condition
while (olf < 5); // On the first pass/loop olf = 1
}
}
//0 から 4 までカウント
default
{
state_entry()
{
integer olf;
do
llSay(0, (string)olf); // olf is still equal to zero at first iteration
while (++olf < 5); // Increments then does the while-test
}
}
//0から4まで数え、ループ中にコメントを追加する(ブロック文のデモ)
default
{
state_entry()
{
integer olf;
do
{ // Curly brackets are required since there is more than one statement within the do-loop
llSay(0, (string)olf);
llSay(0, "looping");
}
while (++olf < 5);
}
}
// do/whileループがwhileループよりも直接役立つ実用的な例:
// センサーイベントには常に入力データが含まれるため、「do」には常に処理するものがあります。
sensor(integer num)
{
if (num > 12)
num = 12;
do
{
// --num decrements num before using it to pick up a detected avatar's name. Thus we retrieve #11 through #0
gNameList += [llGetSubString(llDetectedName(--num), 0, 23)]; //sometimes avatar names are too long for dialog display
gKeyList += [llDetectedKey(num)]; //we will dialog select avatar by name, but still need their key
//even if their name has not been truncated above
} while (num > 0);
llDialog(llGetOwner(), "Choose an avatar.", gNameList, gDlgChan); //channel is pre-defined when llSensor is triggered
}