- 1
Hi! I have a question, kindly check the question's description.
Me : Hi guys, I have a question. Senior programers in the house : Go ahead little programmer, we can solve any problem. What have you? The_question : How can i dynamically name variables in a loop?đđđ
2 RĂ©ponses
+ 3
Please specify a relevant programming language in your post's tags, in order to narrow the scope of discussion topic. What you ask for may or may not be possible, depending on the language involved.
https://code.sololearn.com/W3uiji9X28C1/?ref=app
+ 2
Michael Aladejobi your profile indicates that you are studying Python and C. In Python your program can dynamically build a string that can run a Python script when passed into the exec() function. You can generate variable names however you please to build that script.
In C, it does not make sense to dynamically name variables. Variable names are used for your convenience when writing code. After that, the compiler translates them into addresses, which is all that matters during execution.
Typically, when you have a bunch of values associated with each other such that you could automatically generate their names in a loop, that is the time to implement a list, tuple, or array and address the values by their index number within the iterable variable.