-
June 16th, 2013, 12:04 PM
#1
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?
-
June 19th, 2013, 09:21 AM
#2
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
-
June 20th, 2013, 08:32 AM
#3
Re: Creating a variable using a variable?
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) , but thx for the try anyway
-
June 20th, 2013, 01:55 PM
#4
Re: Creating a variable using a variable?
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.
-
June 20th, 2013, 02:20 PM
#5
Re: Creating a variable using a variable?
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 :/
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|