# Skipping sections of a notebook automatically

I have a notebook which allows to set some parameters at the start, and then does computations depending on these parameters. It is a long notebook and for readability it is broken up into sections and subsections etc.

Now for some values of the parameters, certain sections of calculations are not necessary, so I want to skip these whole sections, without having to put them in one evaluation cell. Is this possible?

I tried putting this piece of code in the beginning of the section I want to skip:

 If[p>3,Goto[nextsection]];


And in the following section,

 Label[nextsection];


This is the effect I want, except that it doesn't work, because for Goto the label needs to be in the same input cell.

When I run it manually I can of course just skip it, or comment it out, but I'm running this notebook automatically (using the code in my own answer to my question here) so I want to automate this skipping as well.

• Not an answer, but in the long run you might consider consolidating your code into Functions or Modules or even packages to facilitate repeated evaluation. This should also help eliminate errors caused by wrong evaluation order etc.. – Yves Klett Nov 29 '15 at 13:46
• If you mean you've put the code in different cells, then you can use functions like NotebookFind and SelectionEvaluate. But it seems less trouble to do as Yves suggests. – Michael E2 Nov 29 '15 at 14:38
• Maybe this can be marked as a duplicate, what do you think? How to evaluate an input cell automatically after evaluating the previous one. The question is not the same but the answer is similar. – Kuba Nov 30 '15 at 7:44
• This is indeed close to an answer, but not quite yet. I want to be able to evaluate everything (ctrl+A and shift enter or have another notebook do this) and skip a subsection depending on some condition. Your answer to the other question doesn't seem to achieve this. If I use NotebookLocate["next"]; SelectionEvaluate[EvaluationNotebook[]]; in the beginning of the section that is to be skipped, and i mark some cell in the next section with next, the effect is something else. Everything is evaluated, and after this is done, the cells marked next are evaluated again – Jansen Nov 30 '15 at 20:15
• @Jansen What about putting a prolog cell as a first cell in those conditional sections, if the condition is not met it could drop evaluation from parent group and move to next. Is that ok? – Kuba Dec 1 '15 at 7:45

I put conditional code in a delayed Block, and added a toggler which defines wither that block is to be run on "Evaluate Notebook" or not:
If you'd rather use global variables in your conditional Block use:
testX := Block[{},