Ok adding to your example it would look something like the following, only this still is not right. It has been decades since I messed with it but a rough example:
Code:
get_key(){
### I forget the exact code in BASH but it gets a single keystroke from the keyboard
### placing into a variable without the need to use the enter keys.
### Lets just say I am getting "1" and "2" and placing it into x
}
main(){
while ($x == 1); do
echo "1"
done
while ($x == 2); do
echo "2"
done
while ( #It has been too many years but there was some BASIC command that flagged the keyboard interrupt); do
x=$get_key
wend
}
main
In BASIC there was a special function attached to WEND compared to DO that ties into the function of flagging keyboard interrupts. So it was used as an interrupt to a loop without destroying the loop. In more simple terms, real time keyboard input.