Skip to main content
FW version: Stable

Cycles

info
  • Code blocks and functions are first uploaded to MCU memory and then executed.
  • Other code is executed line by line.

branch <arg>

Branches (jumps) to a desired place in the running script. If the branch command is executed outside of a code block, the last entered main code block (if exists) is called and executed. Further determine where to branch with <arg>, which can be one of these (or combinations):

  • s or b - branch to the beginning of the current block.
  • s- - branch to one line before the beginning of the current block (can be used to create a while cycle).
  • s-- - branch to two lines before the beginning of the current block.
  • s---, s---- ...
  • s+ - branch to one line after the beginning of the current block.
  • s++, s+++ ...
  • e - branch to the end of the current block.
  • q - branch to the end of the main block.
  • p - branch to the beginning of the parent block.
  • pe - branch to the end of the parent block.
  • pp - branch to the beginning of a parent parent block.
  • ppe, ppp ...
  • n - branch to the beginning of the next child block.
  • ne - branch to the end of the next child block.
  • nn - branch to the beginning of a next next child block.
  • nne, nnn ...

Code blocks

Code blocks start with { and end with a pairing closing bracket }. Multiple sub-blocks and sub-sub-blocks could be created inside the main block of code. A Code block is considered to be the parent of the code blocks declared inside it. If a code block A is a parent of code block B, then code block B is a child of code block A. Further, the first child is considered a next child, the second is considered a next next child, and so on.

{ # start of the main block

{ # start of block 1

{ # start of block 2
...
} # end of block 2


{ # start of block 3

{ # start of block 4
...
} # end of block 4

} # end of block 3

} # end of block 1


{ # start of block 5
...
} # start of block 5

} # end of the main block
  • block 1 is a parent of blocks 2 and 3
  • block 3 is a parent of block 4
  • block 2 is a next child of block 1
  • block 3 is a next next child of block 1
  • block 3 is a parent of block 4
  • block 1 is a parent parent of block 4
  • block 1 is the next child of the main block
  • the main block is a parent parent parent of block 4

Example 1

This example implements a simple while cycle. This cycle will print out numbers from 10 to 1 and at the end print this is the end.

var a
set a 10

{
if a {
echo $a
set a a-1
branch s-
}

echo this is the end
}

Result:

10
9
8
7
6
5
4
3
2
1
this is the end

Example 2

  • First, let the user to input the desired length of the array then, create an array of variables
  • Finally, variables in the array are initialized one by one, from beginning to end.
  • The user is prompted to input each variable in the array
@c #send interrupt in a case other script is running
@! #machine log-in as guest

echo \12 #clear term window

{ #begin of code block
echo Example start.

#create variable that holds number of variables in array and let the user to input the number of variables
var i uint8
echo Input length of an array:
set i $?
echo #print newline

#create array of floats, number of floats are equal to i
var my_array.$i float

#create auxiliary variable for cycle control and initialize it to 0
var j int8
set j 0

#block2 is the of code that runs repeatly in cycle, until all variables in array are initialized:
{ #begin of block 2

#let user to input value of variable in array
echo Input value for element on position $j :
set my_array.$j $?
echo #print newline

#add 1 to auxiliary variable which is used for indexing the array
set j j+1

#check if the indexing variable is still smaller than length of the array if it is,
#jump to begin of this block and repeat whole procedure for next variable in array
#if the auxiliary variable rechad end of the array, no jump occurs and
#script continues with commands following the block 2
if i>j branch b
} #end of block 2

#next commands could be placed here to run after a cycle, for example, array content could be printed:
echo The array content is:
echo $my_array

echo End
}

Result:

Example start.
Input length of an array:
2
Input value for element on position 0 :
1
Input value for element on position 1 :
5
The array content is:
1.0,5.0
End