I have the following structure of code:
for
for
for
for
{
things
if(condition1||condition2)
}
And basically that "if" checks 2 variables that depends of every loop before it, but only have to be checked if the user said so at the beginning of the program, otherwise that "if" is pointless.
I could use if(boolean&&(condition1||condition2)) which would work great except for the fact that it would be checked for every single iteration of all the loops.
So my question is: Is there a way to get C++ to disable that "if" completely (without checking a condition every loop) if the user said so, without repeating itself with and without the if??? Like, for example:
if(boolean)
{
all the fors
things
if(conditio1||condition2)
}
else
{
all the fors
things
}
This works fine but if I have to make any change in the future, I would have to write it 2 times with the possibility of forgetting about the second time or making mistakes. And I also have other 3 parts of code with the same issue, so the code would get really long.
Aucun commentaire:
Enregistrer un commentaire