Search

Loop

This document describes how to create a loop by block coding.
Index

For

A repeat statement is a syntax that allows a specific part of the code to be repeated under certain conditions.

1) For Statement Blockset

The repeat statement consists of initial values (init), condition, counter, and statements to be executed if true.

2) Condition Blockset

Defines conditions to be applied to loop elements.
Click the button to add or delete conditions in logical comparison form (&&, ||)
Below is an example using the For Statement Blockset.
No.
Detail
1
Create Array Data by declaring the variables Array1 and Array2.
2
Declare a HashMap type variable result.
3
Set the initial value (i=0) of the For statement.
4
Set the condition of the For statement. - Repeat the For statement when the value of variable i is less than the number of elements in array Array 1.
5
The For statement is an increment or decrement. - When repeating For statements, increase the value of variable i by 1 each time.
6
Command statement for For statement. - Add a HashMap element to the variable result, where the i-th element of array1 is key and the i-th element of array2 is the value.
7
Check the results on the Testbed.

Foreach

The Foreach statement is used to repeat the number of elements in an array or the number of properties of an object.
The Foreach block set consists of an array object (element), an index (key) of the array, a value (value), and a statement (statement).
Below is an example using the Foreach statement blockset.
No.
Detail
1
Declare HashMap type variable ResponseData.
2
Declare the variable HashMapData and create Array Data.
3
Specifies the array object (HashMapData) to apply the Foreach statement.
4
The Key(index) of the element obtained when traversing the element through the Foreach statement is stored in a variable called KeyName.
5
The Value of the element obtained when traversing the element through the Foreach statement is stored in a variable called ValueName.
6
A Command statement in the Foreach statement. - Add a HashMap element with KeyName as key and ValueName as value to the variable ResponseData - Clean up Key in the form of KeyName via the String Concat (text integration) block.
7
Check the results in Testbed.

Control Block

1) Break

If certain conditions are met, exit the repeat statement without further circulation.

2) Continue

If certain conditions are met, skip the contents below Continue and start the next iteration.