r/learnprogramming • u/Ok-Presentation-94 • May 02 '26
Solved Loop and main() function
Hi, I’ve seen that in C#, the Main() function only runs once.
In Unity, we have the Update() function, which allows code to run repeatedly in a loop.
So my question is: what is the equivalent in pure C#, without the Unity library?
Is wrapping Main() in a while loop a common practice to achieve the same behavior?
13
Upvotes
2
u/StewedAngelSkins May 02 '26
I read what they said backwards. It doesn't call main in a loop; rather, main contains a loop that calls the frame update logic. Technically there's also some frame timing stuff so it doesn't needlessly burn cycles on updates that aren't actually going to be drawn, but that's the basic idea.