vendredi 26 avril 2019

Why can't you make conditional assignment in short hand IF statement?

I'm trying to update softcount for my Blackjack game to account for Aces being played (value 11 or 1). When using the short-form IF statement, why is the first line of code incorrect, but the second line is okay to use? Is this type of if statement limited?

(counter > 1) ? (softcount+=1) : (softcount+=value); // bad


softcount += (counter > 1) ? 1 : value; // good

Aucun commentaire:

Enregistrer un commentaire