Prevent evaluation of certain cells / code segments
In addition to Jens comment:
This is how you can find the cellproperties:
EDIT(1):
I've got an idea on how to improve the variable based method. You could create a wrapper function call it: code
wich holds additional code, that can be turned on/off like this:
evaluationRoutines = {1 -> True, 2 -> False, 3 -> True};
ClearAll[code]
SetAttributes[code, HoldAll]
code[args__][i_Integer] :=
If[i /. evaluationRoutines, ReleaseHold[args]]
With this you write the code separated by ;
into the first bracketslot of code[][]
. You define the number of the evaluation rutine within the second bracketslot. This might look a little awkward... Why not using the first slot for the number instead? Because the Attribute HoldAll will only work for the first brackets, e.g. for args. The use of the attribute HoldAll
is important to keep the arguments unevaluated until we want to evaluate them.
This is an example of how you would use it:
In:
Clear[i]
code[
i = 1;
i++;
Print[i]
][2]
Out:
no Output was generated, because the value 2 is replaced by False as defined in evaluationRoutines
and If evaluates to Null. You can see that the code has not been evaluated by the colloring of i. It is still blue so it has no associated value.
Clear[i]
code[
i = 1;
i++;
Print[i]
][1]
Out:
2
Now the block of code was evaluated and i
now has the value 2
EDIT(2):
If you dont like to give evaluationRoutines as rules use this one:
evaluationRoutines = {True, False, True};
ClearAll[code]
SetAttributes[code, HoldAll]
code[args__][i_Integer] :=
If[evaluationRoutines〚i〛, ReleaseHold[args]]