Câu lệnh continue được dùng để bỏ qua một lần lặp nếu một điều kiện cụ thể xảy ra. Nếu điều kiện được thỏa mãn, lần lặp đó sẽ bị bỏ qua và tiếp tục từ lần lặp tiếp theo.
Dưới đây là mã triển khai câu lệnh continue trong JavaScript:
Ví dụ
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: blueviolet; } </style> </head> <body> <h1>Câu lệnh continue trong JavaScript</h1> <div class="result"></div><br /> <button class="Btn">Click Here</button> <h3>Nhấn nút trên để in các số chẵn từ 1 đến 30</h3> <script> let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); BtnEle.addEventListener("click", () => { for (let i = 1; i < 30; i++) { if (i % 2 !== 0) { continue; } resEle.innerHTML += i + " "; } }); </script> </body> </html>
Kết quả

Khi nhấn nút 'Click Here':
