Variable name incrementation

Discussion in 'C++' started by everett, Feb 13, 2004.

  1. everett

    everett Guest

    How do you increment a variable name in loop. For example I have a
    variable K1 and I want to increment the name by one everytime I go
    through the loop to K2, K3, K4 and so on. Thanks.
     
    everett, Feb 13, 2004
    #1
    1. Advertising

  2. everett

    Andreas Guest

    everett wrote:

    > How do you increment a variable name in loop. For example I have a
    > variable K1 and I want to increment the name by one everytime I go
    > through the loop to K2, K3, K4 and so on. Thanks.


    I think the simplest way is useing an array. But if you'll stick to names
    generative programming in conjunction with loop unrolling may help you

    Andreas
     
    Andreas, Feb 13, 2004
    #2
    1. Advertising

  3. "everett" <> wrote in message
    news:...
    > How do you increment a variable name in loop. For example I have a
    > variable K1 and I want to increment the name by one everytime I go
    > through the loop to K2, K3, K4 and so on. Thanks.


    You cannot increment a variable name, in a loop or anywhere else.

    Perhaps you need to use an array instead of a variable. Post the code you
    are having difficulty with.

    john
     
    John Harrison, Feb 13, 2004
    #3
  4. everett

    Jon Bell Guest

    In article <>,
    everett <> wrote:
    >How do you increment a variable name in loop.


    You can't.

    >For example I have a
    >variable K1 and I want to increment the name by one everytime I go
    >through the loop to K2, K3, K4 and so on. Thanks.


    Why not use an array, or better, a vector?

    vector<double> K(10);

    for (int pos = 0; pos < 10; ++pos)
    {
    // do something with K[pos]
    }

    --
    Jon Bell <> Presbyterian College
    Dept. of Physics and Computer Science Clinton, South Carolina USA
     
    Jon Bell, Feb 13, 2004
    #4
    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. Ralf Hildebrandt

    Re: Nested For Loop incrementation

    Ralf Hildebrandt, Jul 2, 2003, in forum: VHDL
    Replies:
    3
    Views:
    3,481
    Aaron McFarland
    Jul 3, 2003
  2. Petterson Mikael

    Confusing incrementation

    Petterson Mikael, Sep 6, 2006, in forum: XML
    Replies:
    0
    Views:
    395
    Petterson Mikael
    Sep 6, 2006
  3. Max

    Incrementation

    Max, Mar 23, 2007, in forum: Java
    Replies:
    3
    Views:
    371
  4. sam
    Replies:
    4
    Views:
    315
    Andre Kostur
    Jun 26, 2007
  5. Replies:
    4
    Views:
    309
    santosh
    Apr 26, 2008
Loading...

Share This Page