For a start, you have only three images... (yes, sometime I like to state the obvious...

)
It isn't mandatory for such a small number of images, but otherwise you would benefit from using an array.
See
From several variables to arrays for information.
I fail to see the point of the img == img test, it is always true. And you start a loop with while, and exit immediately with break... You should look at the
if statement instead!
You should have a counter indicating which is the current image number, and so what is the next image to display. Increment this counter when x is above your threshold, and when reaching the max number, reset it to the first value.
But you risk to have images changing too quickly if you don't have a timer or a frame counter.