Sometimes when you’re coding, you find yourself toggling a block of code on or off by commenting it. Most development environments make this pretty easy with a button or shortcut that will comment or uncomment a selected block.
However, it can be handy to know that there’s a way to achieve the same thing by setting up your block comments in such a way that they can be enabled or disabled by adding or removing a single “/”.
Here’s how it looks with the code commented out:
/*
thisIsCodeIWant.toToggle(onOff);
andMoreCodeHere();
//*/ |
You can uncomment the code block by adding a “/” at the start of the block comment like so:
//* thisIsCodeIWant.toToggle(onOff); andMoreCodeHere(); //*/ |
After I posted this, hbb reminded me of a related commenting trick. With the following set-up you can toggle between two code blocks by adding a “/”.
//* thisIsCodeBlock(1); moreCode(); /*/ thisIsCodeBlock(2); andMore(); //*/ |
Just remove the “/” at the beginning of the first block comment to swap code blocks.
/* thisIsCodeBlock(1); moreCode(); /*/ thisIsCodeBlock(2); andMore(); //*/ |
This is a pretty basic tip, but I’ve found that not all developers are aware of it, so I thought it couldn’t hurt to share it.

