compiler quiestion; turning code on and off

Hey all, I’m not sure how to search for this.

I’m wondering if there is a way to easily turn off blocks of code at compile time instead of commenting it out.

For example, I want to be able to change global variable from 0 to 1 or from false to true and it remove code from the sketch in various places at once.

#define codeSkip 1


void loop () {

do a bunch of stuff
do a bunch of stuff

do some other stuff
if (codeSkip) {
 skip all of this
}
do some stuff

withOUT having an if/then statement each time through the loop, such that it was never compiled.

I’ve seen code in libraries along the lines of #ifanddef or something like that. Is that what that means?
Thanks in advance.

Google "c++ preprocessor" and I think you'll get some good links.

#define something


#ifdef something   

//  compile one thing

#else

//  compile a different thing

#endif
#define CODE_SKIP


void loop () {

do a bunch of stuff
do a bunch of stuff

do some other stuff
#ifdef CODE_SKIP
 skip all of this
#endif
do some stuff

Just comment the define to not skip it

#define compileOptionalCode

#ifdef compileOptionalCode
// This code will be compile only if compileOptionalCode is defined
#endif

#ifdef tests if the expression is defined. You don't even need to give codeSkip a value. Just like a regular if, you can have an #else but you can leave that part out. You MUST have a #endif at the end.

A long long time ago, the "#" had to go in the first column, so you often see these processor directives ignore the indent pattern of the actual program inside the directives.

#if can also be used to generate more complex expressions rather than just looking to see if something is defined.

Thank you all for the prompt replies!