1.학습내용
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 0번째 부터 무한반복된다.
let i = 0
while(true){
alert(`${i}번째 반복문입니다.`)
i =i+1
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let i = 0
while(confirm("계속 진행을 원하시면 확인을 누르세요")){
alert(`${i}번째 반복문입니다.`)
i = i + 1
// i++ (i = i + 1과 동일한 결과. i + 1 만 사용할 경우 무한으로 빠지게 된다.)
}
</script>
</body>
</html>
while- array 문
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let i= 0
const array =[1, 2, 3, 4, 5, 6, 7]
while(i < array.length){
alert(`${i}번째 반복입니다.`)
console.log(array[i])
i = i + 1
}
</script>
</body>
</html>
for-if 문
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<Script>
// for(let j =0; j<10; j++){
// alert(`${j}번째 반복문`)
// break;
// }
// while에 true를 이용하여 무한반복을 하되, for를 이용하여 조건을 만들어 줄 수 있다.
for(let j =0; j<10; j++){
alert(`${j}번째 반복문`)
const tf =confirm("계속하시겠습니까?")
if(!tf){
break
} j = j + 1
}
</Script>
</body>
</html>
for-continue
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<Script>
for(let j =0; j<10; j++){
alert(`${j}번째 반복문`)
continue
const tf =confirm("계속하시겠습니까?")
if(!tf){
break
} j = j + 1
}
</Script>
</body>
</html>
for 중첩 반복문
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<Script>
let result="" //변수 선언
for(let i=1; i<10; i++){
for(let j=0; j<i; j++){
result += "*" //첫 번째 시행// 동일: result = result+ "*"
}
result += "\n" //두 번째 시행
}
console.log(result)
</Script>
</body>
</html>
function
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//1) 프로시저 함수
const f =function(){ //함수 선언, 익명 함수
console.log("실행문1")
console.log("실행문2")
console.log("실행문3")
}
f() //함수 호출
// console.log(f) //console.log로도 함수를 호출 할 수 있다. 함수 내용을 보여줌
// 2) 수학적 함수
// const fk =function(x){
// return x +5
// }
// console.log(fk(5))
// 5라는 매개변수가 있으며 const fk에 5가 전달되고 5+5=10 으로 되고, console.log가 10으로 나타남
</script>
</body>
</html>
프로시저 함수
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<Script>
let limit = 0
const f =function(){
let result = 0
for(let f = 1 ; f<limit; f++){
result= result+f
}
console.log(f)
}
f()
</Script>
</body>
</html>
2.어려운점
함수부분이 어렵다
3.해결방법
프로시저함수나 수학적 함수 문법 암기
함수부분부터 이해력이 떨어짐 주말활용중요