Creating a variable using a variable?
Hi guys.
Okay, so I am quite new to programming, and i was wondering if there is any way to create a variable using a variable in the name?
So f.x. if you wanted to create an int named nr(x), and x was 1, you would get an int variable named nr1. How would you do this?
Re: Creating a variable using a variable?
Its possible, I dont know the EXACT code off by heart, but one way that I do it, is I make 2 variables, like bob, and nr, and then x, so id have like
int bob = 0;
int nr = x;
int x = 1;
so now, nr will always be 1, and now I can use bob to call x any time in my code
Then you could even use a Setinel Loop for use of it for example... Hope that coulda helped, again sorry I cant provide the legit code to copy n paste
Re: Creating a variable using a variable?
Quote:
Originally Posted by
Dibbie
Its possible, I dont know the EXACT code off by heart, but one way that I do it, is I make 2 variables, like bob, and nr, and then x, so id have like
int bob = 0;
int nr = x;
int x = 1;
so now, nr will always be 1, and now I can use bob to call x any time in my code
Then you could even use a Setinel Loop for use of it for example... Hope that coulda helped, again sorry I cant provide the legit code to copy n paste
I'm not sure if it's what i looked for, and i dont know what a Setinel Loop is (ill google it) :D, but thx for the try anyway :D
Re: Creating a variable using a variable?
Quote:
Originally Posted by
akiel123
Hi guys.
Okay, so I am quite new to programming, and i was wondering if there is any way to create a variable using a variable in the name?
So f.x. if you wanted to create an int named nr(x), and x was 1, you would get an int variable named nr1. How would you do this?
I believe what you are trying to ask is if you can create an int called x as 1, and then create a new int called nr1 but using x in place of the 1. Well, if this is what you are asking then the answer is no. You can use a similar technique to call upon ints already created (ex: int nr1, nr2, nr3; ) but you cannot create them in this sense. Let me know if this is what you were asking for or if not, you have any other ways to clarify it.
Re: Creating a variable using a variable?
Quote:
Originally Posted by
Mercifies
I believe what you are trying to ask is if you can create an int called x as 1, and then create a new int called nr1 but using x in place of the 1. Well, if this is what you are asking then the answer is no. You can use a similar technique to call upon ints already created (ex: int nr1, nr2, nr3; ) but you cannot create them in this sense. Let me know if this is what you were asking for or if not, you have any other ways to clarify it.
Yea i think thats it - so nr[x] will be nr[whatever-x-is] upon creation :/