How do I do this program?

But I only want x to reach 4... then the program stops.