Hi! I have a question, kindly check the question's description. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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?😂😂😂

9th Mar 2022, 2:24 PM
Michael Aladejobi 🇳🇬
Michael Aladejobi 🇳🇬 - avatar
2 Answers
+ 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
9th Mar 2022, 2:59 PM
Ipang
+ 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.
9th Mar 2022, 3:19 PM
Brian
Brian - avatar