https://www.youtube.com/watch?v=nl5cz7ueAAA&list=PLgqG2uj21HgkcfVtlr5rPekQl5VWJEnIB&index=15
아래의 코드처럼 배열의 연산을 차례대로 출력을 하려면 코드가 길어지게 된다. 하지만 반복문을 이용하게 된다면 쉽게 차례대로 출력할 수 있다.
#include <iostream>
int main(){
using namespace std;
char a[10] = {'a', 'b', 'c', 'd', 'e'};
cout << a[0] << endl;
cout << a[1] << endl;
cout << a[2] << endl;
cout << a[3] << endl;
cout << a[4] << endl;
return 0;
}
for문을 사용할 때 알아야 할 3가지에 대해 알아보겠다.
#include <iostream>
int main(){
using namespace std;
for(int i =0; i < 5; i++){
cout << i << endl;
}
}