that's like asking when is it the right time to use insert-name-of-a-spice-here, when the recipe calls for it or your taste suggests it may do the trick
some guideline can be deduced, though
Jump a large interval up and then fall back by semi-tone, e.g. C-A-Ab-G
Jump down a large interval and climb back up by semi-tone, e.g.C-F-F#-G
move up or down by semi-tone to change the tension of the melody over the chord, e.g C-C#-D or E-Eb-D or G-Gb-F or F-F#-G are all reasonable uses.
As with any melodic device, sometimes it may be that you are stepping back slightly before returning to the departure note, e.g. C-G-Gb-G or G-D-Eb-D
Underlined notes are in the octave below any notes preceding them
notation and audio later