Hello, i´ve always wondered if the for and while loops went through the whole loop in one frame or it looped once per frame. right now i have no uses for this information but i guess at some point it could be usefull.
All the code located in a function which is called every frame ( such as Update()
and OnGUI()
) will be called once a frame, including loops.
For instance, the following script displays the value of i
10 times, every frame:
void Update(){
for(int i=0; i<10; i++){
Debug.Log(i+"
");
}
}
The result of running the game, using this script, during 2 frames will be:
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
Note: Coroutines are an exception for this rule.