Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > elseif problem

Reply
Thread Tools

elseif problem

 
 
simonced
Guest
Posts: n/a
 
      06-02-2006
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[(E-Mail Removed)-2]
@position-=1

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

end

I really don't get why.
Any Idea ?

Thanks by advance.

 
Reply With Quote
 
 
 
 
S P Arif Sahari Wibowo
Guest
Posts: n/a
 
      06-02-2006
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/
 
Reply With Quote
 
 
 
 
Dmitry Buzdin
Guest
Posts: n/a
 
      06-02-2006
Ruby uses "elsif" keyword instead of "else if" combination.

Dmitry

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      06-02-2006
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[(E-Mail Removed)-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
 
Reply With Quote
 
simonced
Guest
Posts: n/a
 
      06-02-2006

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[(E-Mail Removed)-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.

 
Reply With Quote
 
Alec Ross
Guest
Posts: n/a
 
      06-02-2006
In message <(E-Mail Removed) .com>,
simonced <(E-Mail Removed)> 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[(E-Mail Removed)-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
 
Reply With Quote
 
Erik Veenstra
Guest
Posts: n/a
 
      06-03-2006
> if char=~/\w|\s/i then
> @buffer+=char
> @position+=1
>
> else if id==14 then
> #backSpace
> @buffer=@buffer[(E-Mail Removed)-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[(E-Mail Removed)-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/

 
Reply With Quote
 
simonced
Guest
Posts: n/a
 
      06-03-2006
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[(E-Mail Removed)-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[(E-Mail Removed)-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/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the last elseif run or not? fl VHDL 6 02-28-2013 10:28 AM
Newbie: if / elseif planetthoughtful Ruby 10 03-16-2007 11:05 PM
elseif v. elsif ?? 7stud 7stud Ruby 83 03-13-2007 02:58 PM
ElseIF or Case Statement? Leon ASP .Net 5 12-17-2004 05:33 PM
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments