# An error I can't find

**URL:** <https://www.ruby-forum.com/t/an-error-i-cant-find/107232>\
**Category:** Ruby\
**Created:** [June 19, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232 "2007-06-19T13:06:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [June 19, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232/1 "2007-06-19T13:06:19Z")

</div>

Hello, there’s certainly a monstrous error I don’t see in :  
\<% for i in @news %\>  
\<% if dern\_cat != i.categorie %\>  
\<% case i.categorie %\>  
\<% end %\>  
\<% end %\>  
\<% end %\>

I’ve removed all the code I could and don’t understand why the case  
i.categorie produce a syntax error, unexpected tIDENTIFIER, expecting  
kWHEN

What is that syntax error ?

Thank you

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [June 19, 2007, 1:40pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232/2 "2007-06-19T13:40:28Z")

</div>

This is just what I found, maybe it’ll help:

[http://www.ruby-doc.org/docs/UsersGuide/rg/control.html](http://www.ruby-doc.org/docs/UsersGuide/rg/control.html)

l- ooking at their example it seems the syntax should be:  
case  
when  
end

I guess that’s why it’s saying it’s expecting “when”.

Zouplaz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
Hello, there’s certainly a monstrous error I don’t see in :

\<% for i in @news %\>  
\<% if dern\_cat != i.categorie %\>  
\<% case i.categorie %\>  
\<% end %\>  
\<% end %\>  
\<% end %\>

I’ve removed all the code I could and don’t understand why the case  
i.categorie produce a syntax error, unexpected tIDENTIFIER, expecting  
kWHEN

What is that syntax error ?

Thank you

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [June 19, 2007, 1:51pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232/3 "2007-06-19T13:51:32Z")

</div>

Zouplaz schrieb:

> What is that syntax error ?
> 
> Thank you  
> The correct Syntax would be something like this (not tested):  
> \<% for i in @news %\>  
> \<% if dern\_cat != i.categorie %\>  
> \<% case i.categorie %\>  
> \<% when bar then foo %\>  
> \<% end %\>  
> \<% end %\>  
> \<% end %\>

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [June 19, 2007, 2:01pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232/4 "2007-06-19T14:01:33Z")

</div>

le 19/06/2007 13:46, Daniel K. nous a dit:

> > i.categorie produce a syntax error, unexpected tIDENTIFIER, expecting  
> > \<% end %\>  
> > \<% end %\>  
> > \<% end %\>

I removed the ‘when’ statements just to have the shortest source code…  
with

when ‘foo’  
doit()  
when ‘bar’  
dont()

the error is the same

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [June 19, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232/5 "2007-06-19T14:21:35Z")

</div>

that’s the correct synthax, working with me without problems:

for i in @news do  
if dern\_cat != i.categorie then

case i.categorie  
when bar :foo  
end

end  
end

If you still have problems post your whole code and the exact and whole  
errormessage you are getting!

Zouplaz wrote:

> > > I’ve removed all the code I could and don’t understand why the case  
> > > \<% when bar then foo %\>  
> > > dont()
> 
> the error is the same

–  
greets

```
                 one must still have chaos in oneself to be able to

```

give birth to a dancing star

---

<div class="post-metadata">

**Author:** ![Zouplaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a4c791/32.png) [@Zouplaz](https://www.ruby-forum.com/u/Zouplaz)\
**Post date:** [June 19, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/an-error-i-cant-find/107232/6 "2007-06-19T15:12:47Z")

</div>

Dear Zouplaz,

it seems you opened a case-end statement and incorporated  
when-end statements into it.  
But the when part doesn’t end in ‘end’, but in the next when  
statement:

case condition

```
when 1

  puts "First thing."

when 2

  puts "Second thing."

```

else

```
  puts 'you didn\'t satisfy the condition!!!!'

```

end

Best regards,

Axel
