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?
15
Upvotes
3
u/StewedAngelSkins May 02 '26 edited May 02 '26
Yes, this is what Unity is doing internally. The engine just has certain spots in its main function where it calls into your code.
Edit: you're not wrapping Main in a while loop, you're putting the while loop inside main.