<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,minimal-ui:ios"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href=""> <script src=""></script> </head> <body> </body> <script> /* break和continue -break: break用来终止Switch和循环语句; break执行后当前的Switch或循环会立刻终止; break会终止离它最近的循环 -continue: continue用来跳过当次循环 */ for (let i = 0; i < 5; i++) { console.log(i) if (i == 3) { break //break虽然写在if里,但是是对循环生效的,不是对if生效的 console.log('跳出了') } } for (let i = 0; i < 5; i++) { for (let j = 0; j < 5; j++) { if (j == 2) { break //break虽然写在if里,但是是对循环生效的,不是对if生效的 console.log('跳出了') } console.log('内层循环==>'+j) } console.log(i) } for (let i = 0; i < 5; i++) { if (i == 3) { continue //continue虽然写在if里,但是是对循环生效的,不是对if生效的 console.log('跳出了') } console.log('continue'+i) } </script> </html>
标签:12,console,log,--,JS,break,continue,let,循环 From: https://www.cnblogs.com/SadicZhou/p/16935793.html