• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the ? and : operators

 
Gaia Nathan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me what the ? and : operators do?
I can't find a reference to them.
 
Sunetra Saha
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they make up a consolidated if-else syntax.
You can write the following if statement
if(condA)
{ statementA;
}else statementB;
as
condA?statementA:statementB
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Actually, the ? : is called the Conditional Operator. Some code to illustrate what Sunetra wrote:

Hope this helps!
//Kaspar
 
Gaia Nathan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sunetra, Kaspar. Both your replies made it very clear for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic