How can I stop a program from logging data into an SD card?

Because, I'm logging emg data and I'm not sure how long is the time that a loop should run, (if I where to do it that way).
I haven't worked much with arduino IDE, I come from programming python and not very familiar with C++.

I have a vague idea that I should set up some interrupts when I press a key or a flag but not sure how to proceed. I'm not asking for a code just directions.

thanks