elseif problem

Discussion in 'Ruby' started by simonced, Jun 2, 2006.

  1. simonced

    simonced Guest

    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[-2]
    @position-=1

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

    end

    I really don't get why.
    Any Idea ?

    Thanks by advance.
     
    simonced, Jun 2, 2006
    #1
    1. Advertising

  2. 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/
     
    S P Arif Sahari Wibowo, Jun 2, 2006
    #2
    1. Advertising

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

    Dmitry
     
    Dmitry Buzdin, Jun 2, 2006
    #3
  4. 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[-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
     
    Robert Klemme, Jun 2, 2006
    #4
  5. simonced

    simonced Guest

    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[-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.
     
    simonced, Jun 2, 2006
    #5
  6. simonced

    Alec Ross Guest

    In message <>,
    simonced <> 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[-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
     
    Alec Ross, Jun 2, 2006
    #6
  7. > if char=~/\w|\s/i then
    > @buffer+=char
    > @position+=1
    >
    > else if id==14 then
    > #backSpace
    > @buffer=@buffer[-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[-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/
     
    Erik Veenstra, Jun 3, 2006
    #7
  8. simonced

    simonced Guest

    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[-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[-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, Jun 3, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon

    ElseIF or Case Statement?

    Leon, Dec 16, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    486
    Dan Bass
    Dec 17, 2004
  2. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    550
    Bullschmidt
    May 11, 2004
  3. 7stud 7stud

    elseif v. elsif ??

    7stud 7stud, Mar 7, 2007, in forum: Ruby
    Replies:
    83
    Views:
    848
    Samantha
    Mar 13, 2007
  4. planetthoughtful

    Newbie: if / elseif

    planetthoughtful, Mar 14, 2007, in forum: Ruby
    Replies:
    10
    Views:
    222
    Chad Perrin
    Mar 16, 2007
  5. fl
    Replies:
    6
    Views:
    367
    HT-Lab
    Feb 28, 2013
Loading...

Share This Page