increment/decrement

Discussion in 'Ruby' started by Teodor Carstea, Dec 4, 2009.

  1. what is Ruby's style of increment/decrement?

    I mean like in C++

    someVar++
    or someVar--
    --
    Posted via http://www.ruby-forum.com/.
     
    Teodor Carstea, Dec 4, 2009
    #1
    1. Advertising

  2. Teodor Carstea

    Paul Smith Guest

    On Fri, Dec 4, 2009 at 12:22 PM, Teodor Carstea <> wrote:
    > what is Ruby's style of increment/decrement?
    >
    > I mean like in C++
    >
    > someVar++
    > or someVar--


    someVar += 1

    Or, more likely, work out why you don't really need to increment and
    use something else (hint, if you're incrementing an array index,
    you're probably doing it wrong)

    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >




    --
    Paul Smith
    http://www.nomadicfun.co.uk

     
    Paul Smith, Dec 4, 2009
    #2
    1. Advertising

  3. Teodor Carstea

    Mike Stok Guest

    Mike Stok, Dec 4, 2009
    #3
  4. 2009/12/4 Mike Stok <>:
    >
    > On Dec 4, 2009, at 7:22 AM, Teodor Carstea wrote:
    >
    >> what is Ruby's style of increment/decrement?
    >>
    >> I mean like in C++
    >>
    >> someVar++
    >> or someVar--

    >
    > Take a look at http://ruby-doc.org/docs/Newcomers/ruby.html#operators which includes "To increment a number, simply write x += 1T."


    Teodor, if you now start wondering why there is no i++ in Ruby please
    see the recent thread "Ruby doesn't implement x++ for Fixnum's because
    ???".

    http://groups.google.de/group/comp....3e9e57d1?lnk=gst&q=increment#b83161b23e9e57d1

    Cheers

    robert

    --
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
     
    Robert Klemme, Dec 4, 2009
    #4
  5. Hi,

    Am Freitag, 04. Dez 2009, 21:34:31 +0900 schrieb Paul Smith:
    > On Fri, Dec 4, 2009 at 12:22 PM, Teodor Carstea <> wrote:
    > > what is Ruby's style of increment/decrement?
    > >
    > > I mean like in C++
    > >
    > > someVar++
    > > or someVar--

    >
    > someVar += 1


    You may also say

    someVar = someVar.succ

    With strings even this works:

    str = "A0000"
    str.succ!

    For iterating use somethig like Fixnum#times or Array#each.

    Bertram


    --
    Bertram Scharpf
    Stuttgart, Deutschland/Germany
    http://www.bertram-scharpf.de
     
    Bertram Scharpf, Dec 4, 2009
    #5
    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. Hendrix
    Replies:
    1
    Views:
    1,696
    Ivan Vecerina
    Jun 29, 2003
  2. Mark Turney
    Replies:
    11
    Views:
    4,304
    dibeas
    Nov 13, 2006
  3. John
    Replies:
    4
    Views:
    1,157
    Vladimir Marko
    May 17, 2005
  4. Ian Pilcher

    Increment, decrement, overflow, and underflow

    Ian Pilcher, Jan 20, 2005, in forum: C Programming
    Replies:
    5
    Views:
    592
    CBFalconer
    Jan 21, 2005
  5. lovecreatesbeauty
    Replies:
    8
    Views:
    1,696
    Old Wolf
    Sep 12, 2005
Loading...

Share This Page