4 ms·
Perl has the same type of syntax: print "true" if (a < b); I recall seeing dialects of BASIC back in the 70s which supported it as well. Who knows, maybe
by tasty_freeze 10y ago
Perl has the same type of syntax:
print "true" if (a < b);
I recall seeing dialects of BASIC back in the 70s which supported it as well. Who knows, maybe this is where Perl got it from.
I use the post conditional most often in perl in this way:
foreach my $foo (@collection) {
next if (I-dont-care-about-this-$foo);
next if (another-reason-for-ignoring-$foo);
do_something($foo);
}
- Mordak 10y agoI use ruby's trailing conditionals exactly this way all the time - it makes me happy to see someone else using the same pattern. I also use it at the start of functions in order to sanity check arguments: def do_something(arg1, arg2) return false if arg1.is_invalid return false if arg2 < sane ... end The trailing `unless` is also handy, and I find it a bit nicer to read compared to a negated `if`.