How do I invert the /testfor command's result? (1.12 and below)

The way to accomplish this is to use a second (chain, unconditional) command block checking with the command /testforblock <coordinates of first command block> command_block * {SuccessCount:0}, which makes it succeed if the first command block fails (because it's SuccessCount is 0), and fail if the first command block suceeded, allowing you to properly condition things off of the inverse.

If the first command block (that you want to fail) is a repeating or chain command block, then you have to use repeating_command_block or chain_command_block (respectively) instead of just command_block, but the command otherwise works the same.


Adding onto @pppery's answer, you should place the second and third commands in a different chain. If you place them in one chain, this will happen when the /say was supposed to run:

REPEAT, UNCONDITIONAL: /testfor @e[type=MyEntity] || FAILS: The entity was not found.
CHAIN, UNCONDITIONAL: /testforblock x y z command_block * {SuccessCount:0} || PASSES: The first command block did not pass.
CHAIN, CONDITIONAL: /say The first command block failed. || Does not run. The first command failed, and for this to run, both previous ones had to pass, which is impossible since at least one command is bound to fail.

If you change it into two chains, this happens:

REPEAT, UNCONDITIONAL: /testfor @e[type=MyEntity]
REPEAT, UNCONDITIONAL: /testforblock x y z command_block * {SuccessCount:0} || PASSES: The first command block did not pass.
CHAIN, CONDITIONAL: /say The first command block failed. || RUNS: All previous commands passed.