As always, there a many approaches you could take to achieve this.
One of the simplest ones to me is to use a control flag that you flip on/off each time you press the joystick button.
Of course there is a huge gotcha in the example above. What happens if you hold the button down for more than a few milliseconds (which is more than likely)? The while loop would flip the flag on every iteration which means that the flag could get flipped many many times each time you press the button because of how much faster the microcontroller is than your thumb.
We can introduce another flag to track whether or not we just flipped the flag to avoid the issue.
Here is a better example showing the second flag:
The code above is just an example, so feel free to experiment what works best for you.