//while문으로 바꾸자
for (let i=0; i<10; i++){
console.log("출략");
}
let i=0; while(i<10){ console.log("출력"); ㅑ++; }
for (let i=0; i<20; i= i+2){
console.log("출력");
}
출력
출력
출력
출력
출력
출력
출력
출력
출력
출력
//for of 반복문을 결과가 같은 for in 반복문으로 변경
let array = [52, 273, 32, 93, 103];
for (let element of array){
console.log(element);
}
let array = [52, 273, 32, 93, 103]; // for (i in array){ console.log(array[i]); }
가장 작은 수와 가장 큰 수를 출력하는 프로그램 작성
//배열을 선언
let array = [273, 52, 103, 57, 271];
//최솟값과 최댓값을 계산합니다.
let min = Number.MAX_VALUE;
let max = Number.MIN_VALUE;
//구성
for (i in array){
if (min > array[i]){
min = array[i];
}
if (max < array[i]){
max = array[i];
}
}
console.log(`가장 큰 수: ${max}`);
console.log(`가장 작은 수: ${min}`);
배열 역순 출력
array = [52, 71, 32, 103, 273, 93]; for (i in array){ console.log(array[array.length -i -1]); }