# Not understanding this way of proving undecidability of the termination problem

I am reading some slides on Algorithm to understand why termination is an undecidable problem. The slides say the following:

– Assume termination(P) always terminates and returns true iff P always terminates on all input data;

– The following program yields a contradiction

while termination(P) skip;


But I do not see what kind of contradiction there. Any idea?

Still, to answer your question: denote by $$Q$$ the program you describe. Then $$Q$$ is a valid program, that takes as input another program $$P$$, and works as above.
Now ask yourself - what would $$Q$$ do if you gave it its own encoding $$Q$$? Would it terminate or not?
• If $$Q$$ terminates when given $$Q$$, then the "while" condition would stay true, meaning $$Q$$ would not terminate when given $$Q$$, but this is a contradiction.
• If $$Q$$ does not terminate when given $$Q$$, then the while condition is false, so $$Q$$ does terminate when given $$Q$$, which is again a contradiction.