mardi 15 novembre 2016

Better Coding Practice Than If-Else

Lets say I have this code.

int count = 0;
int id = 1;
count = getCountById(id);

if(count == 0){
 id = 2;
 count = getCountById(id);
  if(count == 0){
    id = 3;
    count = getCountById(id);
  }
}

Is there a better way to do this. Is something like a LOOP and CASE Statement inside better?

Aucun commentaire:

Enregistrer un commentaire