Saflet101Loop

last edited byusericonthelimit on 23-Nov-2009

Loop Structure

With the flow based logic structure in Saflet, you can easily create loops. In this walkthrough, we will go over setting up a loop with a terminating condition.

It can be very easy to infinite loops in Saflets; make sure to check that every loop has a proper/reachable termination path. If a termination condition is not met, Saflet can cause a stackoverflow. This will not affect server as a whole but your operation will most likely not preform as expected.



Walkthrough

Download Saflet Used in this Walkthrough


For this walkthrough; you will need to be connected to a SafiServer (see Connection to SafiServer from SafiWorkshop). You will also need to create a Project/Saflet with the Custom Initiator selected as the starting initiator (See: Creating a Project and Saflet)



First create a Local variable with the name of counter, type of Integer, and an initial value of 0. We'll use this variable to keep track of the loops.



Next, add the following ActionSteps:

Then connect them like so:



In the IfThen ActionStep; enter the following script for the Boolean field:

counter >= 3;




Now in the Assignment ActionStep; set the variable to counter and the Value to the following script:

counter + 1;




Set the message field of the DebugLog step connected to the IfThen false output to the following script:

"The count is currently:" + counter;

...and set the message field of the DebugLog step connected to the IfThen true output to the following script:

"Done with looping at:" + counter;



Your Saflet should be clear of errors:


like the following:



Save and Publish the Saflet

Launch the Saflet with the Custom Initiator Client (Send):



You should see the following in the Console pannel:




As with any Saflet, if you want to see more detail about whats happening: use the Debug feature

 
Download in other Formats:
markup Markup | pdf PDF | swf SWF | html HTML | word Word

comments Comments (0)