I believe the issue with what you're describing is that if you're on a temporary visa, like a student visa, applying for a green card shows intent of immigration so you cannot return to the US on a student visa.
If you have an H-1B already you may be able to do what you're describing. If you're a recent grad in the US this basically locks you out of trying to get a green card until you've already secured an H-1B.