While loop freezing program

Ok, so I’ve got a while loop:

while (currentSuperCode < 1) { superCodeDisplay.enabled = false; }

This is for a clicker game I’m building to learn c#. The idea behind this is that the text for superCodeDisplay is hidden until the clicker game rolls over at 1.0e+303 currentCodeLines, at which point the currentCodeLines are converted into superCode, and the game resets with new features. currentCodeLines are generated by clicking, and click amounts can be upgraded, as well as buying employees, which increase lines per second. There is also a cash element, but that’s irrelevant here.

My issue is that this while loop immediately locks up my program on hitting play. I don’t even have a chance to test the text appearing on rollover, and I can’t figure out why. It’s being called in void Update(). I get no console errors, I get no syntax errors, I hit play, and the program eats RAM until I stop it.

while in programming means “continue to repeat the following block of code (in your case, a single line) for as long as this condition is true”.

From your description, it sounds like currentSuperCode is initially less than 1, so the condition is true, and the loop is entered. But, since there’s nothing in the code block that changes currentSuperCode, the condition will always remain true and the while loop repeats that single line of code forever. No checking for player input, no drawing to the screen, no physics calculations - you’re telling Unity just to run that one line over and over and over. See the problem?

Hello,
Morgrhim!

You need to change currentSuperCode in the while loop,
for example:

while (currentSuperCode < 1) { superCodeDisplay.enabled = false; currentSuperCode+=0.01f; }

So, you need to give an opportunity to exit the while loop, i.e. (currentSuperCode < 1) must become false in some time. Otherwise, you will have endless loop and freeze effect.