continue文を使い、do-while文のループの現在の処理を終了し、次の処理へ移るサンプル。
サンプル
ラベル指定なし
<script type="text/javascript">
var $varA = 1;
do {
if ( $varA == 6 ) {
document . write( $varA++ + ' あと一歩!<br />' );
continue;
}
if ( $varA == 7 ) {
document . write( $varA++ + ' ☆ラッキーセブン☆<br />' );
continue;
}
document . write( $varA++ + ' ・・・<br />' );
} while ( $varA <= 10 );
</script>
var $varA = 1;
do {
if ( $varA == 6 ) {
document . write( $varA++ + ' あと一歩!<br />' );
continue;
}
if ( $varA == 7 ) {
document . write( $varA++ + ' ☆ラッキーセブン☆<br />' );
continue;
}
document . write( $varA++ + ' ・・・<br />' );
} while ( $varA <= 10 );
</script>
↓↓↓出力結果↓↓↓
ラベル指定あり
<script type="text/javascript">
var $varA = 1;
label1:
do {
document . write( '<p>$varA: ' );
document . write( $varA++ );
document . write( '</p>' );
var $varB = 1;
label2:
do {
document . write( '<p> $varB: ' );
document . write( $varB++ );
document . write( '</p>' );
document . write( '<p> $varC: ' );
var $varC = 1;
label3:
do {
document . write( $varC++ + ',' );
if ( $varC > 2 ) {
document . write( '</p>' );
continue label2;
}
} while ( $varC < $varB );
document . write( '</p>' );
} while ( $varB < $varA );
} while ( $varA <= 5 );
</script>
var $varA = 1;
label1:
do {
document . write( '<p>$varA: ' );
document . write( $varA++ );
document . write( '</p>' );
var $varB = 1;
label2:
do {
document . write( '<p> $varB: ' );
document . write( $varB++ );
document . write( '</p>' );
document . write( '<p> $varC: ' );
var $varC = 1;
label3:
do {
document . write( $varC++ + ',' );
if ( $varC > 2 ) {
document . write( '</p>' );
continue label2;
}
} while ( $varC < $varB );
document . write( '</p>' );
} while ( $varB < $varA );
} while ( $varA <= 5 );
</script>
↓↓↓出力結果↓↓↓