mardi 18 octobre 2016

Using a bool for multiple conditions

In effort to make my code look more readable I am trying reduce the number times the conditions are written out for an if statement. The approach so far:

   bool op = token=="+"||token=="-"||token=="*"||token=="/"|| 
          token=="&"||token=="|"||token=="<"||token==">"|| 
          token=="="; 
    ...
    if(op==0){...}

The issue is that token is constantly changing! Is there anyway to work around this?

Aucun commentaire:

Enregistrer un commentaire