From: Chad Perrin Date: 2007-03-15T12:20:19+09:00 Subject: Re: Newbie: if / elseif On Thu, Mar 15, 2007 at 12:12:17PM +0900, Augie De Blieck Jr. wrote: > >if $val =~ /this/i > > puts "this" > >elseif $val =~ /that/i > > puts "that" > >elseif $val =~ /the other/i > > puts "the other" > >end > > Just remember that even when you spell it right, it's going to drop > out of the whole construct just as soon as it fulfills a RegEx. After > it prints "this," it stops looking at any of the other "elsif" > statements. > > That short circuiting is a feature. =) Indeed -- that's the whole point of using elsif rather than just a list of separate if statements. The if/elsif/else construct is used for mutually exclusive flow control, where only one of several is to be executed. Using a series of if statements considers each in a vacuum, in order, while if/elsif/else considers them all as part of a greater whole. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "Real ugliness is not harsh-looking syntax, but having to build programs out of the wrong concepts." - Paul Graham