I'm learning C++ and generally it has good and clear rules - but I'm a little confused about the rules related to semicolon. The following two examples are working fine - but what is the best practice - and what is the logic behind it?
Example1 (without semicolon):
#include <iostream>
using namespace std;
int main () {
for (int i = 0; i < 10; i++) {
if (true) {
cout << i << endl;
}
}
}
Example2 (with 3x semicolon):
#include <iostream>
using namespace std;
int main () {
for (int i = 0; i < 10; i++) {
if (true) {
cout << i << endl;
};
};
};