In fact, it can be like this... When the number of loops is very large, it is more effective; because if you make a judgment once in each loop, it will be judged as many times as there are loops. It is better to skip this judgment directly.
const int max = 10;
for (int i = 0; i < max; i++) {
for (int j = 0; j < i; j++) {
// call function to do something
}
for (int j = i + 1; j < max; j++) {
// call function to do something
}
}
In fact, it can be like this... When the number of loops is very large, it is more effective; because if you make a judgment once in each loop, it will be judged as many times as there are loops. It is better to skip this judgment directly.
if(i==j)continue;
You can use it in two ways, one is @sin’s kind
Another way is:
The former is more concise, especially when the logic is particularly complex, the advantages of the former are better reflected.
@sin’s answer is very good and the efficiency is also reflected.