I do not know what RhinoPython.Host does, but you could just define the number of iterations, like:
import rhinoscriptsyntax as rs
print "This is a test"
ballx = 0 # Ball position variables
bally = 0
ballxmove = 0.3
ballymove = 0.7
i = 0
maxSteps = 200 # number of iterations
while i < maxSteps:
ballx = ballx + ballxmove # Update ball position
bally = bally + ballymove
sph = rs.AddSphere( (ballx,bally,0) ,2)
rs.DeleteObject(sph)
if ballx > 30: # Ball reached screen edges?
ballxmove = ballxmove * -1
if ballx < 0:
ballxmove = ballxmove* -1
if bally > 30:
ballymove = ballymove* -1
if bally < 0:
ballymove = ballymove* -1
i += 1
Sorry if this was not of a help.