💻
javascript
  • 자바스크립트 시작하기
  • 자바스크립트 기초 문법
  • 변수
  • 배열
  • 객체
  • 연산자
  • 조건문
    • if문
    • if ~else문
    • 다중 if문
    • 중첩 if문
    • switch문
    • 삼항 연산자
  • 반복문
    • while문
    • do while문
    • for문
    • 중첩 for문
    • break문
    • continue문
  • 함수
    • 선언적 함수
    • 익명함수
    • 매개변수가 있는 함수
    • arguments 함수
    • 리턴값이 있는 함수
    • 재귀함수
    • 콜백함수
    • 내부함수(스코프)
    • 객체 생성자 함수
    • 프로토타입 함수
    • 화살표 함수
    • 클래스
    • Promise
    • 템플릿 리터럴
  • 내장객체
    • String 객체
      • split()
      • join()
    • Number 객체
    • Date 객체
    • Array 객체
    • Math 객체
    • 정규표현 객체
  • 브라우저 객체
    • window 객체
    • navigator 객체
    • screen 객체
    • history 객체
    • location 객체
  • 문서객체
  • 이벤트
Powered by GitBook
On this page

Was this helpful?

  1. 반복문

중첩 for문

for문 안에 for문을 사용한 것을 중첩 for문이라고 합니다.

중첩for문

for(let i = 0; 1<100; i++){ for(let j = 0; j<100; j++){ //반복코드 } }

for문을 이용해서 1~10까지 출력

for(let i=1; i<=10; i++){
    for(let j=1; j<=10; j++){
        document.write(i+","+j+"<br>");
    }
}
function func5(){
    for(i = 1; i <= 7; i++){
        for(j = 1; j <= i; j++){
            document.write(j);
        }
        document.write("<br>");
    }
}
func5();

구구단

//구구단
// i * j = sum
//i(2~9까지 출력)   for(i=2; i<=9; i++)
//j(1~9까지 출력)   for(j=1; j<=9; j++)
// 2 * 1 = 2    3 * 1 = 3
// 2 * 2 = 4    3 * 2 = 6
// 2 * 3 = 6    3 * 3 = 9
// 2 * 4 = 8    3 * 4 = 12
// 2 * 5 = 10   3 * 5 = 15
// 2 * 6 = 12   3 * 6 = 18
// 2 * 7 = 14   3 * 7 = 21
// 2 * 8 = 16   3 * 8 = 24
// 2 * 9 = 18   3 * 9 = 27

for(let i=2; i<=9; i++){
    for(let j=1; j<=9; j++){
        let sum =i*j;
        document.write(i + "*" + j + "=" + sum);
        document.write("<br>")
    }
}

테이블 만들기

let num = 1;
let table = "<table border='1'>";

    for(let i=1; i<=10; i++){
        table += "<tr>";
        for(let j=1; j<=7; j++){
            table += "<td>"+ num +"</td>";
            num++;
        }
        table += "</tr>";
    }
    table += "</table>"

document.write(table);
Previousfor문Nextbreak문

Last updated 4 years ago

Was this helpful?