Well. Loop without bracket can easily get messed up, especially when programmers get tired.
But the compiler can understand it.
Example 1: A complete line that ends with ;
and also immediately follows a for statement belongs to the scope of the for statement. But the line after it won't. Just try to compile it and run it.
#include <iostream>
int main(void){
for (int i = 0; i < 10; i++)
std::cout << "in scope of for" << std::endl;
std::cout << "out of scope of for" << std::endl;
}
Example 2: Same for the if
statement
#include <iostream>
int main(void){
if (1 == 1)
std::cout << "in scope of if" << std::endl;
std::cout << "out of scope of if" << std::endl;
}
Example 3:
#include <iostream>
int main(void){
int num[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int min = num[0];
for (int i = 0; i < 10; i++)
if (num[i] < min) //this if belong to the for above
min = num[i]; //this line belong to `if` above
//so this line also belong to the `for`
//as the `for` own the `if`
}