「Google Apps Script」while文にcontinueでループの先頭に戻るサンプル

構文
while(条件式) {
if(条件式){処理コード
continue;
}
}
continueを使ってwhileループの先頭に戻ります
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function myFunction() {
let i = 22;
while (i < 25) {
if (i === 24) {
i++;
continue;
}
console.log(i);
i++;
}
}
function myFunction() { let i = 22; while (i < 25) { if (i === 24) { i++; continue; } console.log(i); i++; } }
function myFunction() {
 
   let i = 22;

    while (i < 25) {
        if (i === 24) {
            i++;
            continue;
        }
        console.log(i); 
        i++;
    }
}

結果
22
23

Google Apps Script

Posted by arkgame