is it cleaner to check a condition on a variable than to use a bunch of if statements?

In general, if you have many different cases, then it is preferable to use the CASE statement (‘switch’ in other languages) as DrBwts said. Also, as Gereon said, in your example you could decrease the cases you check. So for your example it would look something like this:

CASE MaxContaminationCode OF
  ContaminationClass := '000';
  ContaminationClass := '00';
0..12: // if you ONLY want 0 to 12, otherwise use ELSE here
  ContaminationClass := INT_TO_STRING(MaxContaminationCode);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top