Changing variables in for loop

if i'm writing a for loop



for (int i=0; i<4; i++)<br>
{

x

...

}

i want to declare variables at the point shown as x. I wasnt the variables to begin as ball- and end with the value of i. so i can have ball0 the first time through, ball1, the second time through, and so on. How do i define the variables so that they'll do this?


Comments

  • Do you mean like this?:



    int ball[4];

    for(int i=0; i<4; i++) {

    ball[i] = i;

    }



    Or what? It is hard to understand your message's purpose.




  • : Do you mean like this?:

    :

    : int ball[4];

    : for(int i=0; i<4; i++) {

    : ball[i] = i;

    : }

    :

    : Or what? It is hard to understand your message's purpose.

    :

    :



    null and void, that's exactly what he means. He wants to have for example a loop which loops 4 times where four different variables will be created. He wants - I think - the variables to have each different names (in my case and your case, 4 variables will be created). You can do it easily in bash scripting in linux, but in C, you'll have to create an array like you did.



    Damn, it's hard to explain, but you're correct I think ;)



    -- Psycho






Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories