Exit play mode with framecount/scripting

I am currently running a simulation which depends on the frame count. I would like to exit play mode when I have reached a certain frame so that the simulation stops automatically. My Update function looks like this:

void Update()
{
        //----code related to simulation, works fine--------
        
        //------------ pause when certain frame is reached 
         if(Time.frameCount == 40)
        {
           //----- Pause ?  
        }
}

I have tried Application.Quit() but it seems it is not the answer to my question.

Application.Quit() is ignored when playing in the editor. It should work if you make a build and play it.