how to change variable name in loop?

 

i'm very sorry if its a basic question, but i got stuck with that.

My question is: how to change variable name in loop, for example:

for (a=1;a=7;a++)

{

variable(here next number "a" taken from loop)

}

i'm not writing about using arrays, just want to test many variables in one loop.

i've searched throught documentation and forum but didnt find anything.

thanks a lot for any help

regards

 
oromek wrote >>

i'm very sorry if its a basic question, but i got stuck with that.

My question is: how to change variable name in loop, for example:

for (a=1;a=7;a++)

{

variable(here next number "a" taken from loop)

}

i'm not writing about using arrays, just want to test many variables in one loop.

i've searched throught documentation and forum but didnt find anything.

thanks a lot for any help

regards

Try using the switch function in the loop like this

for(a=1;a<=7;a++)

{

switch (a)

{

case 1:

some evaluation for whe a = 1;

case 2:

some evaluation for when a = 2;

etc.

}

}

whocares

 
oromek:

i'm very sorry if its a basic question, but i got stuck with that.

My question is: how to change variable name in loop, for example:

for (a=1;a=7;a++)

{

variable(here next number "a" taken from loop)

}

i'm not writing about using arrays, just want to test many variables in one loop.

i've searched throught documentation and forum but didnt find anything.

thanks a lot for any help

regards

This is a very strange question and it is not really clear what you are trying to do.

You cannot change a variable's name -- ever. You can change the content or value of a variable like this ...


string strArray[]={"cat", "fat", "hat", "mat", "dog","any other string you feel like", "another string", "and another"};

for( int n=0; n<7; n++ ){
string result= strArray[n];
Print( result );
}


This is probably not what you are after, but if you elaborate on what exactly you are trying to do, maybe somebody can help.

 

thanks guys for quick feedback, i will try to describe it in more exhaustive way:

let say i have 10 variables: val1, val2 to val10

I want to make many operations on this variables, and not repeat many the same code lines where only variable name is changing, thats why i want to use loop


for( int n=0; n<10; n++ ){

if (val"n"<val"n+1") {so something}

....

}

i wrote wrong in first post that i want to change variable name, in fact i want to cycle throught many variables inside loop and during every loop step use other variables

hope it make sense

regards

 
oromek:

thanks guys for quick feedback, i will try to describe it in more exhaustive way:

let say i have 10 variables: val1, val2 to val10

I want to make many operations on this variables, and not repeat many the same code lines where only variable name is changing, thats why i want to use loop


for( int n=0; n<10; n++ ){

if (val"n"<val"n+1") {so something}

....

}

i wrote wrong in first post that i want to change variable name, in fact i want to cycle throught many variables inside loop and during every loop step use other variables

hope it make sense

regards

Well the obvious answer is to make your named variables an array of variables so instead of calling it


var1 you call it var[1]

var2 is var[2]


Then you can index the variables by number rather than by name.

 
dabbler:

Well the obvious answer is to make your named variables an array of variables so instead of calling it


var1 you call it var[1]

var2 is var[2]


Then you can index the variables by number rather than by name.

i'm adapting someone's code, but your reply gave me idea to make array from values of this variables, if i cannot use them directly.

I think that resolves my problem.

Thank you for that and happy new year!!! ;)

regards

 

helo sir i want to hide the code,then this code works in only one system only,thank you

 

helo sir i want to hide the code,then this code works in only one system only,thank you