mercredi 11 août 2021

Whats the best way to account for every possibility for two booleans

So I have run into this a few times now and was wondering if there is some kind of smart way to do it? I mostly program in C#, C++ and JavaScript so a cool method in any of those languages would be helpful. I'm primarily looking for speed, but if there are other things I should be cognisent of I'd love to know about them. I'll show you an example of what I write generally:

if(bool0 || bool1)
{
   if(!bool0)
   {
      // do stuff
   }
   else
   {
      if(!bool1)
      {
         // do stuff
      }
      else
      {
         // do stuff
      }
   }
}

The other thing I'm wondering is, could this be done in a switch statement? Probably not best practice but I thought it was an interesting idea.

Aucun commentaire:

Enregistrer un commentaire