You'll need a boolean variable to record if the quit button has been pressed. At the bottom of your loop, check if your variable is true (meaning 'quit' has been pressed) and if so, exit the main loop. There are a number of tutorials available on creating buttons, so I won't explain that.
the basic premise is,
code: |
bool quit_clicked := false
loop
%main program
if quit_clicked = true then
exit;
end if
end loop
|
Alternatively, you can use the 'quit' keyword which terminates the program, but it tells Windows that the program failed/crashed/whatever instead of terminating gracefully.