Skip to main content

Skip

The idea behind the abstraction of skip in the context of a walkers code block is that it tells a walker to halt and abandon any unfinished work on the current node in favor of moving to the next node (or complete computation if no nodes are queued up).

Note

Node/edge abilities also support the usage of the skip directive. The skip merely decides not to use the remaining steps of that ability itself in this context.

Following example demonstrate how the skip command works;

node plain: has number;

## defining the graph
graph example {
has anchor head;
spawn {
n=[];
for i=0 to i<7 by i+=1 {
n.l::append(spawn node::plain(number=i+1));
}

n[0] ++> n[1] ++> n[2];
n[1] ++> n[3];
n[0] ++> n[4] ++> n[5];
n[4] ++> n[6];
head=n[0];
}
}

#init walker traversing
walker init {
root {
start = spawn here ++> graph::example;
take-->;
}
plain {
## Skipping the nodes with even numbers
if(here.number % 2==0): skip;
std.out(here.number);
take-->;
}
}

Expected Output:

1
5
7

Now it is evident when the node number is an even number, the code in the example above skips the code execution for the particular node. The line if(here.number %2 ==): skip; says walker to skips nodes with an even number.

The skip command "breaks" out of a walker or ability rather than a loop, but otherwise has semantics that are nearly comparable to the standard break command in other programming languages.