728x90
반응형
continue
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>continue</title>
  </head>
  <body>
    <h1>continue문</h1>
    <script>
      var exceptNum = 3;
      for (var i = 0; i <= 10; i++) {
        if (i % exceptNum == 0) continue;
        document.write(i + " ");
      }
    </script>
  </body>
</html>​

 

a
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>continue제어문</title>
  </head>
  <body>
    <h1>continue문</h1>
    <p>홀수단, 홀수번째 구구단 출력하기</p>
    <script>
      //label명: 분기점
      gugudan: for (var i = 2; i <= 9; i++) {
        for (var j = 1; j <= 9; j++) {
          if ((i * j) % 2 == 0)
            //i=3,
            //continue;
            continue gugudan; //label로 건너뜀
          document.write(i + " * " + j + " = " + i * j + "<br>");
          if (j == 9) document.write("<hr");
        }
      }
    </script>
  </body>
</html>​
break
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>break</title>
  </head>
  <body>
    <h1>break문</h1>
    <script>
      var lectures = ["html", "css", 123, "jsp"];
      var topic = "123";

      for (var i = 0; i < lectures.length; i++) {
        if (lectures[i] == topic) {
          document.write(topic + " 과목은 " + (i + 1) + "번째 과목입니다.");
          break;
        }
      }
    </script>
  </body>
</html>​

 

aa
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>break문</h1>
    <script>
      gugudan: 
      for (var i = 2; i <= 9; i++) {
        document.write(i + "단<br>");

        for (var j = 1; j <= 9; j++) {
          if (i > 3) break;
          document.write(i + " * " + j + " = " + i * j + "<br>");
          if (j == 9) document.write("<hr>");
        }
      }
    </script>
  </body>
</html>

728x90
반응형

'[JS]' 카테고리의 다른 글

[JS] function1  (0) 2024.02.28
[JS] array  (0) 2024.02.27
[JS] for  (0) 2024.02.27
[JS] while, do~while  (0) 2024.02.27
[JS] 조건문  (0) 2024.02.27

+ Recent posts