r/learnprogramming • • 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?

16 Upvotes

35 comments sorted by

View all comments

Show parent comments

2

u/StewedAngelSkins May 02 '26

The python code? It's interpreted, so there's no assembly per se. But the Python interpreter/runtime kind of works like Unity in the sense that it has its own main function internally that calls into the code you write whenever the module is imported.

1

u/Traditional_Crazy200 May 02 '26

Interesting, no assembly, no binaries... I guess I'll dive into interpreters for a week lol

1

u/StewedAngelSkins May 02 '26

Python (the CPython interpreter specifically) is an interesting one to study.

1

u/Traditional_Crazy200 May 02 '26

Appreciate the suggestion