continue 문은 특정 조건이 발생하는 경우 한 반복을 건너뛰는 데 사용됩니다. 조건이 충족되면 해당 반복을 건너뛰고 다음 반복에서 계속됩니다.
다음은 JavaScript에서 continue 문을 구현하는 코드입니다 -
예시
<!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>Continue statement in JavaScript</h1>
<div class="result"></div><br />
<button class="Btn">Click Here</button>
<h3>Click on the above button to print even numbers from 1 to 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> 출력

'여기를 클릭' 버튼을 클릭하면 -
