At least the procedure used to be that one would try to get an appointment at the US consulate in one's home country and then arrange the trip around it. Also, at least in my experience (but importantly, not with this administration) was that one was never required to leave the US.
The main constraint is re-entry into the US and being able to travel outside the US. If one stayed here, there was no problem switching schools, programs, jobs, adjusting status to permanent residency or naturalization. On the other hand, for re-entry, one needs a valid visa stamped on a passport which necessitated a trip to one's home country. This stamping visit could be unpredictable.
Ideally, one would like to travel freely to see family and friends but I see a lot of comments implying that one is forced to leave. It might be true now but a lot of comments here are conflating several issues together.