jeudi 5 avril 2018

shortcut for repetitive else if statement

I have to write repetitive else if conditions like:

  if (d_hand[1]==1){
    state=score(p_hand)-1
  } else if (d_hand[1]==2){
    state=19+score(p_hand)
  } else if (d_hand[1]==3){
    state=39+score(p_hand)
  } else if (d_hand[1]==4){
    state=59+score(p_hand)
  } else if (d_hand[1]==5){
    state=79+score(p_hand)
  } else if (d_hand[1]==6){
    state=99+score(p_hand)
  }

Do you know if it could be written more efficiently/shortly? I thought about doing a loop of if but it would be less efficient since every statement would have to be examined.

Aucun commentaire:

Enregistrer un commentaire