# Missing kEND for if statement, but not for a case statement?

**URL:** <https://www.ruby-forum.com/t/missing-kend-for-if-statement-but-not-for-a-case-statement/107935>\
**Category:** Ruby\
**Created:** [June 27, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/missing-kend-for-if-statement-but-not-for-a-case-statement/107935 "2007-06-27T18:10:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 27, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/missing-kend-for-if-statement-but-not-for-a-case-statement/107935/1 "2007-06-27T18:10:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 27, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/missing-kend-for-if-statement-but-not-for-a-case-statement/107935/2 "2007-06-27T18:15:25Z")

</div>

On 6/27/07, Nathan T.-Hoover [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 27, 2007, 6:25pm UTC](https://www.ruby-forum.com/t/missing-kend-for-if-statement-but-not-for-a-case-statement/107935/3 "2007-06-27T18:25:26Z")

</div>

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.
