Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   elseif problem (http://www.velocityreviews.com/forums/t830754-elseif-problem.html)

simonced 06-02-2006 05:01 AM

elseif problem
 
Hello.

I have a complie error on this simple code :

#si c'est un caractere ?
if char=~/\w|\s/i then
@buffer+=char
@position+=1

else if id==14 then
#backSpace
@buffer=@buffer[0..@buffer.length-2]
@position-=1

else
puts "caractere non reconnu : #{id}"

end

I really don't get why.
Any Idea ?

Thanks by advance.


S P Arif Sahari Wibowo 06-02-2006 06:27 AM

Re: elseif problem
 
On Fri, 1 Jun 2006, simonced wrote:
> I have a complie error on this simple code :


use "elsif"?

--
(Stephan Paul) Arif Sahari Wibowo
_____ _____ _____ _____
/____ /____/ /____/ /____
_____/ / / / _____/ http://www.arifsaha.com/

Dmitry Buzdin 06-02-2006 06:36 AM

Re: elseif problem
 
Ruby uses "elsif" keyword instead of "else if" combination.

Dmitry


Robert Klemme 06-02-2006 08:19 AM

Re: elseif problem
 
simonced wrote:
> Hello.
>
> I have a complie error on this simple code :
>
> #si c'est un caractere ?
> if char=~/\w|\s/i then
> @buffer+=char
> @position+=1
>
> else if id==14 then
> #backSpace
> @buffer=@buffer[0..@buffer.length-2]
> @position-=1
>
> else
> puts "caractere non reconnu : #{id}"
>
> end


Use "elsif" or "case"

case
when /\w|\s/i =~ char
then
...
when id == 14
then
...
else
...
end

Regards

robert

simonced 06-02-2006 05:25 PM

Re: elseif problem
 

Robert Klemme viết :
> simonced wrote:
> > Hello.
> >
> > I have a complie error on this simple code :
> >
> > #si c'est un caractere ?
> > if char=~/\w|\s/i then
> > @buffer+=char
> > @position+=1
> >
> > else if id==14 then
> > #backSpace
> > @buffer=@buffer[0..@buffer.length-2]
> > @position-=1
> >
> > else
> > puts "caractere non reconnu : #{id}"
> >
> > end

>
> Use "elsif" or "case"
>
> case
> when /\w|\s/i =~ char
> then
> ...
> when id == 14
> then
> ...
> else
> ...
> end
>
> Regards
>
> robert


elseif if not working, I don't understand why, that's why I also tried
"else if".
but case is working fine. I just didn't know we could make tests with
when oher than === (that's described in my reference book).

thanks for all this help, I can go on now.
Regards.

ced.


Alec Ross 06-02-2006 06:46 PM

Re: elseif problem
 
In message <1149269107.233000.129240@h76g2000cwa.googlegroups .com>,
simonced <simonced@gmail.com> writes
>
>Robert Klemme vi0 >> simonced wrote:
>> > Hello.
>> >
>> > I have a complie error on this simple code :
>> >
>> > #si c'est un caractere ?
>> > if char=~/\w|\s/i then
>> > @buffer+=char
>> > @position+=1
>> >
>> > else if id==14 then
>> > #backSpace
>> > @buffer=@buffer[0..@buffer.length-2]
>> > @position-=1
>> >
>> > else
>> > puts "caractere non reconnu : #{id}"
>> >
>> > end

>>
>> Use "elsif" or "case"
>>
>> case
>> when /\w|\s/i =~ char
>> then
>> ...
>> when id == 14
>> then
>> ...
>> else
>> ...
>> end
>>
>> Regards
>>
>> robert

>
>elseif if not working, I don't understand why, that's why I also tried

no --^ 'e' here. Fixes the problem. No?
>"else if".
>but case is working fine. I just didn't know we could make tests with
>when oher than === (that's described in my reference book).
>
>thanks for all this help, I can go on now.
>Regards.
>
>ced.
>


--
Alec Ross

Erik Veenstra 06-03-2006 10:29 AM

Re: elseif problem
 
> if char=~/\w|\s/i then
> @buffer+=char
> @position+=1
>
> else if id==14 then
> #backSpace
> @buffer=@buffer[0..@buffer.length-2]
> @position-=1
>
> else
> puts "caractere non reconnu : #{id}"
>
> end


Proper indentation will get you a clue:

if char=~/\w|\s/i then
@buffer+=char
@position+=1

else if id==14 then
#backSpace
@buffer=@buffer[0..@buffer.length-2]
@position-=1

else
puts "caractere non reconnu : #{id}"

end

Your are missing one end statement at the end...

gegroet,
Erik V. - http://www.erikveen.dds.nl/


simonced 06-03-2006 07:50 PM

Re: elseif problem
 
you're great !
elsif !!! it's cool! I don't get why my reference book didn't explin
it...
and with good indent I could also have the clue;)

thank you very much.

Erik Veenstra viết :
> > if char=~/\w|\s/i then
> > @buffer+=char
> > @position+=1
> >
> > else if id==14 then
> > #backSpace
> > @buffer=@buffer[0..@buffer.length-2]
> > @position-=1
> >
> > else
> > puts "caractere non reconnu : #{id}"
> >
> > end

>
> Proper indentation will get you a clue:
>
> if char=~/\w|\s/i then
> @buffer+=char
> @position+=1
>
> else if id==14 then
> #backSpace
> @buffer=@buffer[0..@buffer.length-2]
> @position-=1
>
> else
> puts "caractere non reconnu : #{id}"
>
> end
>
> Your are missing one end statement at the end...
>
> gegroet,
> Erik V. - http://www.erikveen.dds.nl/




All times are GMT. The time now is 05:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.