条件を変更せずに while ループを途中から再開する方法はありますか?
while(health > 0 &&enemyhealth > 0){
if(attack)
{
attack
}
if(view stats)
{
console.log(stats)
restart loop
}
enemy attack
}
条件を変更せずに while ループを途中から再開する方法はありますか?
while(health > 0 &&enemyhealth > 0){
if(attack)
{
attack
}
if(view stats)
{
console.log(stats)
restart loop
}
enemy attack
}
あなたが望むように聞こえます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
}
...
}
使用するcontinue
while(health > 0 && enemyhealth > 0){
if(attack)
{
attack
}
if(view stats)
{
console.log(stats)
continue;
}
enemy attack
}