• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in EL operator

 
Gurukant Desai
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
While appearing in Marcus Green's quiz question no.5 of EL chapter
<%int i = 1;int j =2;%>
${i < j}
${1 lt 2}

I was expecting answer as "true true" but right answer is "false true"

Can anyone please explain why ${i < j} will evaluate to false?

Thanks in advance
[ May 06, 2008: Message edited by: Gurukant Desai ]
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

if i am not mistaken
<%int i = 1;int j =2;%>
these are variables not attributes. with the EL you can access attributes of four scopes.
so ${i} and ${j} are not defined ... so they are treated as zero.
So ${0 < 0} that's false because zero is equal to zero.
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Any correct solutions to the problem?
Thanks in advance.
 
Kumar Garlapati
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Musab is absolutely correct with bit change in the explaination, except that zero, it doesn't evaluates as zero. It evaluates as blank.

If it evaluates as zero, ${i==j}, should return true, but it's returning as false. i tried.

output is : true
If we remove scriplet from above code, then output is : false.
it means that if i and j are not present in any scope, they are unable to evaluate as any values. so its evaluating as false.
[ May 06, 2008: Message edited by: Kumar Garlapati ]
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with EL null evaluates to false in boolean expressions and to zero in arithmetic operations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic