Syntax
if (score >= 50) { /* pass */ }
for (const auto& item : items) { /* use item */ }Examples
Classifying scores
A small, runnable example of this syntax.
#include <iostream>
#include <vector>
int main() {
std::vector<int> scores{72, 49, 90};
for (int score : scores) {
std::cout << (score >= 50 ? "pass" : "retry") << "\n";
}
}Best practices
- Use braces even for one-line branches and loops; they prevent errors when the body changes later.
- Keep examples small while learning, then combine the idea with a real project.
Runtime & versions
Compiled native applications. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
ISO C++ resources