Hello!
I am confused with the concept of how the For Loop iterates.
I get that the “for” statement will increase the value of the variable “index” (in this case) until the condition becomes false.
What I am thinking is that if the value of “index” increases then won’t the only option be, for example, “index = 2” therefore making “index = 0” and “index = 1” nonexistent because the “for” statement rose the value of “index” up to “2”?
I maybe though that how it works could be:
As the statement is run and, for example, nextStates.Length = 2 it will create multiple versions of the “if” statement below it, each corresponding to one of the options “index=0”, “index=1”, “index=2”.
I just don’t understand how the For loop works conceptually.
Here is the code in question:
var nextStates = state.GetNextStates();
for (int index = 0; index < nextStates.Length; index++)
{
if (Input.GetKeyDown(KeyCode.Alpha1 + index))
{
state = nextStates[index];
textComponent.text = state.GetStateStory();
}
}