loop to generate variables with different values
In a quiz, I have user answers saved in an array. At the end of the quiz, I need to extract individual answers to different variables q1, q2, q3, etc. The quiz may be of different total questions so I need it to adjust based on total questions in it. How can I use loop to create variables and capture the values?
So I'd like to change the following:
var q1:int = userAnswersArray[0];
var q2:int = userAnswersArray[1];
var q3:int = userAnswersArray[2];
var q4:int = userAnswersArray[3];
...
to the loop like the one below:
for (i = 0; i < totalQuestion-1; i++)
{
this["var var q" + i] + ":int" = "userAnswersArray[" + this + "]";
}
It probably has syntax errors that it does not work.
Thanks for your help.