Is it possible to avoid many "ors" (||) in conditions causing the same action? - page 8

 
paladin80:

In my programs, if there are many ifs, I use this construction, with the conditions that will most often give false in the first place:

And if I need to check a lot of if-ops, I use this way:
Thank you, Maxim! But that's no good, because the different conditions I have are not comparable in logic, nor in parameters!
 
alsu:

No, it doesn't work that way. First, there must be something after if(), at least just a semicolon (i.e. an empty operator) . Second, which one of the if's is your else operator meant to belong to? If it refers only to the last one (as you wrote it), then Action will be executed only if the D condition is true provided that A,B and C are false. It is always advisable to place curly braces to see the logic clearly.

If my highlighting is possible, then it's a good idea to do it this way:

if (!A && !B && !C && !D) ;//пустой оператор
else Action();

  

How? Possible? -------------------------- I checked it in code, the compiler gives a warning;

';' - semicolon unexpected C:\Program Files\

If it works, can we put up with the warning too?!

 
borilunad:

If the one I have highlighted is possible, then it would be a good idea to make it so:

How? Possible? -------------------------- Checked in the code, the compiler gives a warning;

';' - semicolon unexpected C:\Program Files\

If it works, can we put up with the warning too?!

if (!A && !B && !C && !D) return(0); //закончение действия программы
else Action();
 
paladin80:

Thank you very much! How easy it is!

However, I had to put this block at the end of the start, because return(0) didn't let anything else work after it.

 
Has anyone measured speed at all? )))
 
TheXpert:
Has anyone measured the speed at all? )))

I'll take a measurement!

I finally measured it! It's 17.26! That's 10 minutes longer than the best if() with no tricks in six months in the tester. Sorry, but it can't be helped! I'll keep digging! Thanks to all! But it's too early to sum it up yet!

 
borilunad:

If the one I have highlighted is possible, then it would be a good idea to make it so:

How? Possible? -------------------------- Checked in the code, the compiler gives a warning;

';' - semicolon unexpected C:\Program Files\

If it works, can we put up with the warning too?!


A warning is given in case someone just put a comma in the wrong place(the empty ';' operator is not often used). This construction works and is perfectly legal.
 
borilunad:
I'll take a measure!

But you have to check all the options. Otherwise you could be wrong.
 
borilunad:

If the one I have highlighted is possible, then it would be a good idea to make it so:

How? Possible? -------------------------- Checked in the code, the compiler gives a warning;

';' - semicolon unexpected C:\Program Files\

If it works, can we put up with the warning as well?!

To make the warnings less annoying, use: {}

if (!A && !B && !C && !D) {} //пустой оператор
else Action();

 
PapaYozh:

To keep warnings from cluttering up your eyes, use {}: {}

Thank you! I'll try those brackets now!