I need a code example of being able to put something in a loop and then being able to disable and enable it by pressing a key.

I know how to enable and disable stuff

Code:
if (GetAsyncKeyState(VK_F11))
                    {
                    if(!keyWasPressed)
                        {
                        keyWasPressed = true;
                            cout << "\n Enabled" << endl;
Skip();
                            Sleep(400);
                        }
                    else
                        {
                        keyWasPressed = false;
                            cout << "\n Disabled" << endl;
                           Sleep(400);
                        }
                    }
But how do i make it so that when they press F11 it constantly does this code
Code:
cout << "\n Enabled" << endl;
Skip();
but as soon as they hit F11 again is disables the loop