• loops(반복문)
    • for loop for (init_expression;test_expression;update_expression){ statement; } init: 처음 한번 실행, test: 더 반복할지 결정, update: 매 루프마다 실행

      • compound statement(block) (복합문) for(~) statement; 위와 같이 한줄만 있으면 중괄호를 생략해도 된다. 그 이유는 중괄호로 묶인 코드는를 하나의 statement이기 때문이다! block를 사용해 변수의 범위를 제한할 수 있다(지역 변수)
      • comma operator 여러개의 expression을 하나로 묶어준다. for(i=0,j=0; i<3; i++, j++){} 이렇게 사용 가능 *for(int i=0, j=0 ~~)와 같이 변수를 초기화 할 때에는 comma operator 아님!
      • range - based for loop int a[3] = {1,2,3}; for(int x:a ) statement; 이렇게 배열의 원소를 하나씩 loop할 수 있다.

      for(int &x: a) statement; 이렇게 하면 원본을 바꿀 수 있다.

      for(int x:{1,2,3}) statement 이렇게 바로 초기화해서 쓸 수 있다.

    • while loop while(expressoin) statement; expression이 참이라면 실행, 반복한다. 거짓이면 끝난다.

    • do-while loop do statement while(expression); statement를 한번 실행하고, while과 동일하게 동작한다.

    • jump statements break, continue

  • Branching statements(선택문)
    • if statement if(expression) statement; else if (expression) statement; else statement;
    • switch - case switch(int expression){ case value1: statement; break; //break 안하면 다음것도 같이 실행 case value2: statement; break; default: statement; //없어도 됨 }
  • File I/O
    • iostream: cout, cin
    • #include <fstream>: 파일 입출력
      • ofstream outfile; outfile.open(”filename”, mode); outfile<<”hello”;
      • ifstream infile; infile.open() infile >> x >> y; if(infile.eof()) file.close();