중첩 for문
for 문안에 for 문을 사용한 것을 중첩 for 문이라고 합니다.
Last updated
Was this helpful?
for 문안에 for 문을 사용한 것을 중첩 for 문이라고 합니다.
Last updated
Was this helpful?
Was this helpful?
for(let i=0; i<100; i++){ // 바깥쪽 for문 for(let j=0; j<100; j++){ // 안쪽 for문 //반복코드 } }
for(i=1; i<=10; i++){
for(j=1; j<=10; j++){
document.write(i+","+j, "<br>");
}
}
// 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(i=2; i<10; i++){
// 세로 10 가로 7
let table = "<table border=1>";
let num = 0;
for(i=1; i<=10; i++){
table += "<tr>"
for(j=1; j<=7; j++){
num += 1;
table += "<td>" +num+ "</td>";
}
table += "</tr>"
}
document.write(table);
function func4(){
for( i=1; i<=7;i++){
for( j=1; j<=i; j++){
document.write("*");
}
document.write("<br>");
}
}
func4();
/*
*
**
***
****
*****
******
*******
*/