「Google Apps Script」while文にbreakでループを抜ける

構文
while(条件式) {
if(条件式) {break;}
}
break文を使って、whileループを抜けます。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function myFunction() {
let n = 10;
console.log("ループを抜ける");
while (true) {
if (n === 13) {
break;
}
console.log(n);
n++;
}
}
function myFunction() { let n = 10; console.log("ループを抜ける"); while (true) { if (n === 13) { break; } console.log(n); n++; } }
function myFunction() {
 
    let n = 10;

    console.log("ループを抜ける");
    while (true) {
        if (n === 13) {
            break;
        }
        console.log(n); 
        n++;
    }
}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ループを抜ける
10
11
12
ループを抜ける 10 11 12
ループを抜ける
10
11
12

 

Google Apps Script

Posted by arkgame