It also works with trinaries as well.
return $i == 1 ? 'red' : $i == 2 ? 'blue' : $i == 3 ? 'green' : $i == 4 ? 'yellow' : 'white';
However, you should only use this sort of syntax if the syntax is short. It easier for a person to read columns up and down then it is from something that goes from one end of the page to the other. Lets change my example to so you see what I mean.
return $i == 1 ? 'red': $i == 2 ? 'blue' : $i == 3 ? 'green' : $i +== 4 ? 'yellow' : 'white'; # God forbid print "This is my very long string that I wish to print out to display + my message on the screen but only when I want it too!" if $i == 1;
The last one is just asking for trouble because you will probably be looking at the print on the front and not notice the if statement on the end.
In reply to Re: Are there any other statements that are like return if...?
by Herkum
in thread Are there any other statements that are like return if...?
by skrapasor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |