- 모르는 것을 검색하는 방법
- 반복문
- 배열
for(let i 초기화 ;조건식; 증감문){
//반복구문
}
for 구문 초기화에서 let 변수 선언을 해줘야한다.
for 문 안에서 let을 붙이지 않으면 자동으로 var가 붙는다.
//초기화
while(조건식){
//증감문
//반복구문
}
초기화
do{
//증감문
//반복구문
}while(조건식)
//조건식에 맞지 않아도, 초기 한번은 반드시 실행된다.
switch(조건문){
case 값1:
//실행구문
[break;]
case 값2:
//실행구문
[break;]
case 값N:
//실행구문
[break;]
default:
//실행구문
[break;]
}
break / continue
1) break 문법
break;
break 레이블; (특정 레이블 문을 빠져나옴)
2) continue
while, do-while, for, 레이블 문을 다시 시작하기 위해 사용
continue;
continue 레이블;
continue와 break문은 반복문에서만 사용한다.
//break
for (i = 0; i < a.length; i++) {
if (a[i] == theValue) {
break;
}
}
//break 레이블
var x = 0;
var z = 0
labelCancelLoops: while (true) {
console.log("Outer loops: " + x);
x += 1;
z = 1;
while (true) {
console.log("Inner loops: " + z);
z += 1;
if (z === 10 && x === 10) {
break labelCancelLoops;
} else if (z === 10) {
break;
}
}
}
//continue
i = 0;
n = 0;
while (i < 5) {
i++;
if (i == 3) {
continue;
}
n += i;
}
//continue 레이블
checkiandj:
while (i < 4) {
console.log(i);
i += 1;
checkj:
while (j > 4) {
console.log(j);
j -= 1;
if ((j % 2) == 0) {
continue checkj;
}
console.log(j + " is odd.");
}
console.log("i = " + i);
console.log("j = " + j);
}
//초기화
for( variable in object ) {
//실행구문
}
function dump_props(obj) {
var result = "";
for (var i in obj) {
result += i;
}
return result;
}
//result : key값 출력, 속성이름 반복
for (variable of object) {
//실행구문
}
//속성값 반복
const array1 = [1, 2, 3];
console.log(array1.unshift(4, 5));
// expected output: 5
console.log(array1);
// expected output: Array [4, 5, 1, 2, 3]
const animals = ['pigs', 'goats', 'sheep'];
const count = animals.push('cows');
console.log(count);
// expected output: 4
console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15
console.log(typeof 'blubber');
// expected output: "string"
@@ 문자열 복습 및 반복문에 대해서 주로 배우고, 배열에 대해서 조금 예습하는 시간을 가졌다. 첫번째 페어분과의 시간을 오늘로서 종료하고 내일은 다른 페어분을 만나게 된다. 리뷰하는 경험도 처음 해보고, 마지막에 헤어지며 페어분과 덕담도 주고 받았다. 앞으로도 지치지 말고 열심히 페어 활동에 참여해야겠다 생각했다. 첫 페어라 모두가 그렇겠지만, 나 역시도 미숙하고 얼떨떨했는데 참여를 열심히 해주신 페어분께 감사드린다.🙇🙇