0

条件を変更せずに while ループを途中から再開する方法はありますか?

while(health > 0 &&enemyhealth > 0){
    if(attack)
    {
        attack
    }

    if(view stats)
    {
       console.log(stats)
       restart loop
    }

    enemy attack
}
4

2 に答える 2

4

あなたが望むように聞こえますcontinue

while (health > 0 && enemyhealth > 0){
   ...

    if (...)
    {
       ...
       continue; // This will skip the rest of the loop body,
                 // check the loop condition again, and keep going
                 // if the while condition is still true
    }

    ...
}
于 2013-05-26T03:42:15.570 に答える
2

使用するcontinue

while(health > 0 && enemyhealth > 0){
    if(attack)
    {
        attack
    }

    if(view stats)
    {
       console.log(stats)
       continue;
    }

    enemy attack
}
于 2013-05-26T03:44:35.103 に答える