Using a toggle switch to run part of a sketch First, I am a beginner for this.  I just ordered my first book on coding Arduino and I'm working through some simple applications using a DS3231 (that has a temperature reading), LCD, MicroSD card module, etc.  My board is a Uno R3.  Currently, I need a sketch to run part of a program which contains a loop to collect data and have this run when a toggle switch is turned on.  So, toggle goes on and part of program runs, toggle goes off and this part exits.
The reason I need a toggle with constant on/off is the problem with G forces and vibration.  I momentary push button input will not be reliable.  Ultimately, all the components will be in a amateur high-power rocket to run a roll control program.
If you can help, I greatly appreciate your assistance.
There are different ways to accomplish the same thing. 

The condition is a flag, or a read port. 

if(digitalRead(inPin))
     {
     // Your first code here.
     }
else 
     {
     // second code
     }


Switch contacts will bounce when opening or closing. You may want to consider that. Usually it is stable within 10 milliseconds. Depending on what you are doing it may or may not be relevant.