vrijdag 5 juni 2009

The else if in Ruby

The basic if structure in ruby looks like listed below. Especially the 'else if' is uncommon: elsif.


if name=='peter'
...
elsif name=='john'
...
end

2 reacties:

sir.Iain zei

I think it needs to be :if name == 'peter' puts nameelsif name == 'john' puts 'Superuser '+nameend
What your trying to do is to set the name variable in an IF, not very good!.
CodeJoust

Stephan zei

sir.lain is right, it should be == and not =. I changed it.