Proving undecidability of a language with mapping reductions
Usually, when the context of the statement &quot;if $M$ accepts $x$&quot; is in a loop simulating the execution of $M$ on $x$, we just mean to say that if the simulation stopped and $M$ accepted/rejected then do something, otherwise just continue simulating (the more precise way of writing this would be to say &quot;if $M$ accepted after $t$ steps then...&quot;).
Your pseudocode doesn't do anything magical, it simply checks at a specific point of the simulation whether or not $M$ already accepted/rejected.