You are here

Modeling 101 for GraphWalker

I wrote prior to the release of GraphWalker 3. So keep in mind the not all information in this article is valid for GW3. I'll make an updated version soon.

Here under some examples on hos to model different “code” structures.

The following examples are without any Graphwalker related constraints. This is only intended for showing how to model the structures. So no Guards,
weights and javascript enabled in these model exambles.


Mind that some of the example models does not comply with the standards of GraphWalker. They are intentionally made out of compliance due to easing
communication of learning point.

Sequential Flow



If – Else structure

Conditional statements are used to perform different actions based on different conditions.

Conditional Statements

Very often when you write code, you want to perform different actions for different decisions.

You can use conditional statements in your code to do this.

In JavaScript we have the following conditional statements:

· Use if to specify a block of code to be executed, if a specified condition is true

· Use else to specify a block of code to be executed, if the same condition is false

· Use else if to specify a new condition to test, if the first condition is false

· Use switch to specify many alternative blocks of code to be executed

The if Statement

Use the if statement to specify a block of JavaScript code to be executed if a condition is true.

Syntax

if (condition) {
//block of code to be executed if the condition is true
}

The matching model structure will look like this.

And going into a little better detail with the model fro Graphwalker. It looks like this.

And to give the view of modeling a “If – else if – else” structure. There is a non Graphwalker example below.


For Loop

Loops can execute a block of code a number of times.

Loops are handy, if you want to run the same code over and over again, each time with a different value.

Code example:

for (statement 1; statement 2; statement 3) {
text += array.length; [i];
}

Statement 1 is executed before the loop (the code block) starts.
Statement 2 defines the condition for running the loop (the code block).
Statement 3 is executed each time after the loop (the code block) has been executed.

While Loop

Loops can execute a block of code as long as a specified condition is true.

The while loop loops through a block of code as long as a specified condition is true.

while (condition) {
code block to be executed
}



Do While / Start Repeat - Loop

The do while construct consists of a process symbol and a condition.

First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again.
This repeats until the condition becomes false. Because do while loops check the condition after the block is executed, the control structure is often also
known as a post-test loop.

Code Example:

do {
// The code..
} while (counter > 0);

Switch Structure

The switch statement is used to perform different action based on different conditions.

Use the switch statement to select one of many blocks of code to be executed.

Code Syntax

switch(expression) {
case n:
code block
break;
case m:
code block
break;
default:
default code block
}

This is how it works:

· The switch expression is evaluated once.

· The value of the expression is compared with the values of each case.

· If there is a match, the associated block of code is executed.

The matching model structure will look like this.

Use today's weekday number to calculate weekday name: (Sunday=0, Monday=1, Tuesday=2, ...)

switch ([Week Day Number]) {
case 0:
// Code for Day 0
break;
case 1:
// Code for Day 1
break;
case 2:
// Code for Day 2
break;
case 3:
// Code for Day 3
break;
case 4:
// Code for Day 4
break;
case 5:
// Code for Day 5
break;
case 6:
// Code for Day 6
break;
}