Answer the question
In order to leave comments, you need to log in
Is it possible to create variables in a loop?
Hello! I ran into such a thing that when creating a simple calculator , I had to put all the code in a while loop . I don't know if it's normal to create variables inside a while loop ?
Answer the question
In order to leave comments, you need to log in
What do you mean by "create variables"? If you mean declaring variables, then this is not just a normal phenomenon, but a recommendation - if you need a variable only in a cycle (and it will not be visible outside the cycle, because the cycle will have its own scope), then it is much better, if you are in a loop and declare it.
The rule is very simple - keep variable declarations close to where they are used, or more precisely, keep variables in the most nested scope, as far as possible according to where they are used.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question