Forum: Ruby missing kEND for if statement, but not for a case statement?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F54bc341bc19c48e5860fda022663795?d=identicon&s=25 Nathan Taylor (shadowcipher)
on 2007-06-27 18:10
(Received via mailing list)
I am having some trouble figuring out why I keep getting an unexpected
kENSURE expecting kEND error.

I have to sets of code and the first set uses a case statement with the
same
amount of end keywords.  This set runs fine.  The second set uses an if
statement and will not pass a syntax check.  Any advice is greatly
appreciated.  I really need to figure out how to go with the if
statement
because the === operator that case statements use do not work the way I
need
them to when a regex object is placed in the right side of the
expression.
This is a rough example of my syntax.  The actual code has different
values
but the structure is the same.  I've used VIM with matchit and can not
find
any errors.

1st set;

begin
    loopbreak = false
    while loopbreak != true
        str = gets
        case(str)
        when 'help', 'HELP'
            puts help
        when 'quit', 'QUIT'
            loopbreak = true
        when 'options', 'OPTIONS'
            puts options
        else
            puts "{#str} is not a valid command"
        end
    end

ensure
    somehousecleaning()
end


2nd set

begin
    loopbreak = false
    while loopbreak != true
        str = gets
        if str =~ /help|HELP/
            puts help
        else if str =~ /quit|QUIT/
            loopbreak = true
        else if str =~ /options|OPTIONS/
            puts options
        else
            puts "{#str} is not a valid command"
        end
    end

ensure
    somehousecleaning()
end
96931bfe0c2948f47a98e15ae52e5637?d=identicon&s=25 Chris Carter (cdcarter)
on 2007-06-27 18:15
(Received via mailing list)
On 6/27/07, Nathan Taylor-Hoover <onebitcipher@gmail.com> wrote:
>         else
>             puts "{#str} is not a valid command"
>         end
>     end
>
> ensure
>     somehousecleaning()
> end
>

The "else if" construct is elsif in ruby.  doing else if will start an
actual new if statement that needs to be ended.
F54bc341bc19c48e5860fda022663795?d=identicon&s=25 Nathan Taylor (shadowcipher)
on 2007-06-27 18:25
(Received via mailing list)
That is excellent.  Thank you.  I thought it was elseif but when I used
that
in my text editor that has support for ruby it did not colorize it as a
keyword, however when I used else if it did so I was mislead into
believing
I had the correct syntax.
This topic is locked and can not be replied to.