The JSP Files (part 2): Attack Of The Killer Fortune Cookies - Lunch In Milan
(Page 5 of 6 )
If you take a close look at the last-but-one example above, you'll notice that the conditional expression
(temp < 25 && temp > 10)
is slightly different from the ones you've been used to
thus far. This is because JSP also allows you to combine multiple conditions into a single expression, with the help of an animal called a "logical operator".
The following table should make this clearer.
Assume delta = 12, gamma = 12 and omega = 9
| Operator | What It Means | Example | Evaluates To |
| && | AND | delta == gamma && delta > omega | delta equals gamma AND delta is greater than omega |
| True && | AND | delta == gamma && delta < omega | delta equals gamma AND delta is less than omega |
| False || | OR | delta == gamma || delta < omega | delta equals gamma OR delta is less than omega |
| True || | OR | delta > gamma || delta < omega | delta is greater than gamma OR delta is less than omega |
| False ! | NOT | !delta | delta doesn't exist |
So, instead of something as ugly as this
<%
if (day == "Thursday")
{
if (time == "12")
{
if (place == "Italy")
{
lunch = "pasta";
}
}
}
%>
you could have something as elegant as this.
<%
if (day == "Thursday" && time == "12" && place == "Italy")
{
lunch = "pasta";
}
%>
Next: Switching Things Around >>
More Java Articles
More By Vikram Vaswani and Harish Kamath, (c) Melonfire