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.