N
N
NickName73312018-02-27 00:40:15
C++ / C#
NickName7331, 2018-02-27 00:40:15

C # (Unity) - What can replace the infinite for loop?

I came across a problem that when using an infinite loop ( for(; ;) ), the game just freezes. Why is this happening? And are there any alternatives to this cycle? I will be glad to help

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xmoonlight, 2018-02-27
@NickName7331

Coroutines and the event model.

#
#, 2018-02-27
@mindtester

well-formulated question, contains at least half of the answer

by the fact that there is no way out of the loop ... is it really hard to guess?
this is a classic mistake . and you don’t need to replace it with anything .. you just need to exit it ( break or return according to some reasonable condition)
ps
if you have already tried to provide an exit, but it doesn’t happen - there is only half a step left until a brilliant insight - the exit condition is not met

P
Peter, 2018-02-27
@Morpheus_God

do
while
or while(true)

M
mefutu, 2018-03-02
@mefutu

It's most likely not the cycle that's to blame. If you perform (rendering frames, logic) in one thread, then of course there will be sagging.
As an option: split into different threads. Or use another engine, for example: monogame, unity...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question