break文で、do-while文のループを終了させるサンプル。
サンプル
ラベル指定なし
<script type="text/javascript">
var $varA = 1;
do {
document . write( $varA++ + ',' );
if ( $varA == 6 ) {
break;
}
} while ( $varA <= 10 );
</script>
var $varA = 1;
do {
document . write( $varA++ + ',' );
if ( $varA == 6 ) {
break;
}
} while ( $varA <= 10 );
</script>
↓↓↓出力結果↓↓↓
ラベル指定あり
<script type="text/javascript">
var $varA = 1;
do {
document . write( '<p>$varA: ' );
document . write( $varA++ );
document . write( '</p>' );
var $varB = 1;
labelA:
do {
document . write( '<p> $varB: ' );
document . write( $varB++ );
document . write( '</p>' );
document . write( '<p> $varC: ' );
var $varC = 1;
do {
document . write( $varC++ + ',' );
if ( $varC > 2 ) {
document . write( '</p>' );
break labelA;
}
} while ( $varC < $varB );
document . write( '</p>' );
} while ( $varB < $varA );
} while ( $varA <= 5 );
</script>
var $varA = 1;
do {
document . write( '<p>$varA: ' );
document . write( $varA++ );
document . write( '</p>' );
var $varB = 1;
labelA:
do {
document . write( '<p> $varB: ' );
document . write( $varB++ );
document . write( '</p>' );
document . write( '<p> $varC: ' );
var $varC = 1;
do {
document . write( $varC++ + ',' );
if ( $varC > 2 ) {
document . write( '</p>' );
break labelA;
}
} while ( $varC < $varB );
document . write( '</p>' );
} while ( $varB < $varA );
} while ( $varA <= 5 );
</script>
↓↓↓出力結果↓↓↓