strange syntax error in while loop

Discussion in 'Ruby' started by laredotornado, Jan 23, 2008.

  1. Hi,

    I'm getting the error

    SyntaxError in OrderController#confirm
    /usr/local/apache2/htdocs/easyrx/app/controllers/order_controller.rb:
    11: syntax error, unexpected kEND
    end ^
    /usr/local/apache2/htdocs/easyrx/app/controllers/order_controller.rb:
    33: syntax error, unexpected $end, expecting kEND

    in this method:

    def confirm
    i = 0
    while params[:prescription_number + i.to_s] != nil and
    params[:description + i.to_s] != nil
    session[:prescription_number + i.to_s] =
    params[:prescription_number + i.to_s]
    session[:description + i.to_s] =
    params[:description + i.to_s]
    i++
    end # line 11
    end

    Thanks for your help, - Dave
    laredotornado, Jan 23, 2008
    #1
    1. Advertising

  2. laredotornado wrote:
    > i++
    > end


    Ruby doesn't have the ++ operator and parses the above as binary plus followed
    by unary plus, i.e. "i + (+end)". Thus the syntax error.

    HTH,
    Sebastian
    --
    Jabber:
    ICQ: 205544826
    Sebastian Hungerecker, Jan 23, 2008
    #2
    1. Advertising

  3. On [Thu, 24.01.2008 02:24], laredotornado wrote:
    > Hi,
    >
    > I'm getting the error
    >
    > SyntaxError in OrderController#confirm
    > /usr/local/apache2/htdocs/easyrx/app/controllers/order_controller.rb:
    > 11: syntax error, unexpected kEND
    > end ^
    > /usr/local/apache2/htdocs/easyrx/app/controllers/order_controller.rb:
    > 33: syntax error, unexpected $end, expecting kEND
    >
    > in this method:
    >
    > def confirm
    > i = 0
    > while params[:prescription_number + i.to_s] != nil and
    > params[:description + i.to_s] != nil
    > session[:prescription_number + i.to_s] =
    > params[:prescription_number + i.to_s]
    > session[:description + i.to_s] =
    > params[:description + i.to_s]
    > i++
    > end # line 11
    > end
    >
    > Thanks for your help, - Dave



    Ruby doesn't know ++, so you have to write i+=1

    --
    Dominik Honnef
    Dominik Honnef, Jan 23, 2008
    #3
    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. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,224
    Tim Slattery
    Mar 30, 2005
  2. Daniel Pitts
    Replies:
    14
    Views:
    1,228
    Patricia Shanahan
    Dec 23, 2006
  3. Uday Bidkar
    Replies:
    4
    Views:
    484
    =?ISO-8859-15?Q?Juli=E1n?= Albo
    Dec 12, 2006
  4. Isaac Won
    Replies:
    9
    Views:
    364
    Ulrich Eckhardt
    Mar 4, 2013
  5. Replies:
    27
    Views:
    313
    Chris Angelico
    May 7, 2013
Loading...

Share This Page