Channi Studies

[C++] Range-based for Loop 본문

C++/반복문 (Loop)

[C++] Range-based for Loop

Chan Lee 2023. 12. 10. 18:40

형식

// FORMAT

for (var_type var_name: sequence){
	statements;	// can use var_name
}

 

예시 코드

// Example Code

#include <iostream>
using namespace std;

int main(){
    vector<int> my_vec {10, 50, 22, 501, 1930};
    
    for (int num:my_vec) {
        cout << num << endl;    // 10\n50\n22\n501\n1930
    }

}

 

'C++ > 반복문 (Loop)' 카테고리의 다른 글

[C++] do-while Loop  (0) 2023.12.12
[C++] While Loop  (0) 2023.12.10
[C++] Conditional Operator (조건 연산자)  (2) 2023.12.08