Well, do you have a copy of the Mach3 manual? If not you need one for a summary of the G code definitions as well as lots of other relevant info.
The G31 Z-3 F20 command does exactly what you say but G31 is a "straight probe" command. While it's moving Mach3 continually monitors the state of the probe input and movement stops when the probe triggers. The value of Z at which trigger happens is written into an internal register though your code doesn't access it, instead just using the value of Z at which the probe stopped (which is probably slightly different as the axis has to decelerate).
The command:
code "G1 Z0.5"
causes the Z axis to move up 0.5 at the last commanded feedrate which is F20 from the G31 command. Usually there's no reason to move so slowly, using G0 just makes the move at the programmed rapid rate.
I'd be nervous BTW of making the probe move at F20, that's 20 inches/minute = 500mm/minute! A more common value would be 50mm/minute, and probe routines often probe at this speed first then take a second go at perhaps 5mm/minute after a very small retract.
I strongly recommend that you learn how G code programming works. You might never actually write a program to make a part, but it is very useful to have some understanding of what the statements in the code produced by CAM means. You could for example be able to answer the questions you asked here!