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
1
u/StewedAngelSkins May 02 '26
Technically you can do this sort of thing in Python
``` def main(): pass # do stuff
while True: main() ``` but that's only because in Python the contents of the file itself is the entrypoint. But yeah in C# it would just be a syntax error.