[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

elseif problem

simonced

6/2/2006 5:01:00 AM

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.

7 Answers

S P Arif Sahari Wibowo

6/2/2006 6:27:00 AM

0

Dmitry Buzdin

6/2/2006 6:37:00 AM

0

Ruby uses "elsif" keyword instead of "else if" combination.

Dmitry

Robert Klemme

6/2/2006 8:19:00 AM

0

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

6/2/2006 5:25:00 PM

0


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

6/2/2006 6:47:00 PM

0

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

6/3/2006 10:29:00 AM

0

> 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.erikve...

simonced

6/3/2006 7:50:00 PM

0

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.erikve...