This is part-tip, part-adventures in code. I found out recently that it is possible to comment out multiple lines of code in Igor and thought I’d put this tip up here.
Multi-line commenting in programming is useful two reasons:
- writing comments (instructions, guidance) that last more than one line
- the ability to temporarily remove a block of code while testing
In each computer language there is the ability to comment out at least one line of code.
In Igor this is “//”, which comments out the whole line, but no more.
This is the same as in ImageJ macro language.
Now, to comment out whole sections in FIJI/ImageJ is easy. Inserting “/*” where you want the comment to start, and then “*/” where it ends, multiple lines later.
I didn’t think this syntax was available in Igor, and it isn’t really. I was manually adding “//” for each line I wanted to remove, which was annoying. It turns out that you can use Edit > Commentize to add “//” to the start of all selected lines. The keyboard shortcut in IP7 is Cmd-/. You can reverse the process with Edit > Decommentize or Cmd-\.
There is actually another way. Igor can conditionally compile code. This is useful if for example you write for Igor 7 and Igor 6. You can get compilation of IP7 commands only if the user is running IP7 for example. This same logic can be used to comment out code as follows.
The condition if 0 is never satisfied, so the code does not compile. The equivalent statement for IP7-specific compilation, is “#if igorversion()>=7”.
So there you have it, two ways to comment out code in Igor. These tips were from IgorExchange.
If you want to read more about commenting in different languages and the origins of comments, read here.
This post is part of a series of tips.