Welcome! Log In Create A New Profile

Advanced

How to have multiple conditions in if statement

Posted by sumitg 
How to have multiple conditions in if statement
June 16, 2009 11:11AM
Hi, looked around but couldn't find an answer: is there any way to have multiple conditions (a and b)/(a or b) in if statements. Or even nested if statements?

I have several checks in location using successive if statements using regexes, each of which sets a value as well. I think I can make things far more efficient by also checking if the value is already set or not. I'm assuming that like other languages, conditions will be evaluated from left-to-right and with shortcut evaluations (so if the first condition, which will be the faster condition to check if my flag is empty, is false, the second one doesn't need to be evaluated in case of an AND, or if the first one is true then the second one can be ignored in case of an OR). For example:

[code]
set $no_cache '';
if ($http_method = POST)
{
set $no_cache '1';
}
if ($request_uri ~ preview=true)
{
set $no_cache '1';
}
[/code]

...and so on...

in the second case, if the condition was:

[code]
if (!$no_cache AND $request_uri ~ preview=true)
{
...
}
[/code]


it would be much more efficient as I save a useless regex in case $no_cache is already '1'. And I have many such comparisions which happen uselessly.

Anyone?

Sumit.



Edited 1 time(s). Last edit at 06/16/2009 11:14AM by sumitg.
Re: How to have multiple conditions in if statement
June 22, 2009 07:08AM
Anyone? Is this not possible? Another case is where I want to check for multuple UAs (to check for mobile browsers)... currently there's multiple if's handling the situation.

There must be a better way!

Sumit.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 173
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready