dimanche 30 mai 2021

What does the "player = (player == 1) ? 2 : 1? [duplicate]

I am beginner programmer and trying to understand the various ways to represent a code written like the one below. I was reading a line of code that was under a while-loop but did not explain what the code below means. I only understand the equality sign but not the "? 2 : 1"

player = (player == 1) ? 2 : 1;

I was browsing the internet but wanted to make sure since its slightly different, but is this the same as to an if statement? Is there another way to present the code above beside the if statement?

if(player % 2) {
   player = 1;
   }
   else {
   player = 2;

Aucun commentaire:

Enregistrer un commentaire