Skip to main content
C++ Code Completion Medium +20 XP

Range-Based For

Complete the range-based for loop.

C++Fill in the blank
vector<int> nums = {1, 2, 3};
for (int n ___ nums) {
    cout << n << " ";
}

Type the missing code

Show answer and explanation

Answer: :

Range-based for uses a colon: for (element : container).

Hint: What separator does range-based for use?

What this challenge tests

Code Completion in C++: loops, range-for.

Related challenges