Update console in the same frame

Hi, I have two loops, one inside other. The process I am doing takes around 9 seconds with 8192 x 8192 iterations. I would like to print a percentage in the outer loop but it seems that console just update on the next frame after the loop.

Pseudo-code:

   for(int i = 0; i < 8192;i++){
        for(int j = 0; j < 8192;j++){
             // Do some crazy stuff here
        }
        Debug.Log(100f * i / 8192f + "%"); /* Doesn't print until next frame*/
   }

I understand why it would be a bad practice to print every time the console updates,in most cases unnecessary and process consuming but since I need it how can I force the console to update? Or I will need to write to a file in the HD to ensure the system stop processing.

Hello.

No, it will not print in next frame. It will print when operation finishes. A frame is a loop of ALL commands of ALL scripts running every frame. C# is a serial programming language. What you need is a parallel programming here. When using loading screen, you can not rely on serial programming. That is why there are Coroutines. Try changing your code to this :

private IEnumerator CrazyStuffRoutine()
{
     for(int i = 0; i < 8192;i++){
         for(int j = 0; j < 8192;j++){
              // Do some crazy stuff here
              Debug.Log(100f * i / 8192f + "%"); /* Doesn't print until next frame*/
              
              yield return null;
         }
    }
}

Yield return null means wait a frame, and continue on the next one. So expect this code to run at your fps speed. Ofcourse you can yield return null every 10 steps or 100. This piece of code is not serial and will not halt your total process until it finishes. To call coroutine just use :

StartCoroutine(CrazyStuffRoutine());

I hope this helps.