I
I
Ilya2021-01-30 16:22:22
Programming
Ilya, 2021-01-30 16:22:22

Is it normal that all my code is in an infinite for loop?

In general terms: I am writing a game in cities with a computer. It is essentially infinite, and therefore I stuffed the entire code of the program into a for loop without parameters. Am I doing the right thing or is there a more elegant solution?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vyacheslav Sad-Zhabka, 2021-02-06
@izem

It's okay, don't sweat it. Thus, for example, all sorts of task schedulers, web servers, etc. are arranged. The main thing is to observe two conditions:
1. Clean up unused memory at each iteration so that there is no memory leak with a large number of them.
2. Provide a condition for exiting the loop in advance. It can also be a simple shutdown of the program through some Ctrl + C in the terminal. The main thing is not to forget to clean the memory here :)

S
SagePtr, 2021-01-30
@SagePtr

Depending on what language you are writing in, if in some bare C / C ++ - then yes, the event processing loop will have to be implemented independently. And if at a higher level, or you use some kind of engine, then most likely, this cycle is already built in there, all that remains is to receive and process the events themselves.

T
taktik, 2021-01-30
@taktik

About the game loop - https://martalex.gitbooks.io/gameprogrammingpatter...

S
Saboteur, 2021-01-30
@saboteur_kiev

Yes, it's quite normal.
But for assumes that you are going to iterate some object, so in such cases it is better to use while true or until false loops.
PS In general, for specifics, it is better to indicate the programming language

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question