• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL ? : Operator

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HD P-448 Q-1

${ (5 + 3 + a > 0) ? 1 : 2}

Is ? : operator in exam? HFSJ doen't talk about it ?
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sandeep,

I honestly do not remember if the ternary operator appears on the actual exam; nor do I remember if HFSJ discusses it. (I'm at work and don't have a copy of the book handy.)

However, this operator behaves the same as the ternary operator in C and Java. The first operand must map to a Boolean value. If the value is 'true' then the second operand is evaluated and returned; otherwise the third operand is evaluated and returned.

In this example ${ (5 + 3 + a > 0) ? 1 : 2} the value returns 1 if 'a' is greater than -8 or 2 if 'a' is less than ro equal to -8. Make sense?

Cheers,
Bryan
[ March 17, 2008: Message edited by: Bryan Basham ]
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bryan,
Thanks for the reply.

I just wanted to know that EL also has ternary operator (?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic