JavaScript break跳出多重循环

http://www.nowamagic.net/javascript/js_JumpLoops.php


多重循环在编程中会经常遇到,那么在JavaScript中如何指定跳出那层的循环呢。其实这也是break的一个用法,下面是一个不错的例子,来自《JavaScript权威指南》,可以参考下:

Code

01

程序运行结果:

view source
print ?
01 i = 0 , j = 0
02 i = 0 , j = 1
03 i = 0 , j = 2
04 i = 0 , j = 3
05 i = 1 , j = 0
06 i = 1 , j = 1
07 i = 1 , j = 2
08 i = 1 , j = 3
09 i = 3 , j = 0
10 i = 3 , j = 1
11 i = 3 , j = 2
12 i = 3 , j = 3
13 final i = 4 , j = 0

你可能感兴趣的:(Javascript)