Loops Component
  • 13 Feb 2023
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

Loops Component

  • Dark
    Light
  • PDF

Article summary

The Loops component is primarily used to perform operations repeatedly in the form of iterations.

While Block

The While statement loops through a block of code as long as a specified condition is true. The do while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.

InputOutputBlock LayoutGenerated Code

Choose the repeater type (while or until),

Boolean (True or False),

The repeater statement.


For while repeater, it will execute the statement until it becomes false. 

For until repeater, it will execute the statement until it becomes true.


 
while (false) {

}

while (!false) {

}

For Block

The For loop loops through a block of code a number of times.

InputOutputBlock LayoutGenerated Code

Variable or number for: (from)input-1,(to)input-2, and (by)input-3

Any code block within "do" statement


For the count repeater, it will execute the given statement block based on "from-to" input values and the step(by) value. 

We can have high to low or low to high.



  
var i;


function er_3eff8d47_6dd5_4f07_92d0_fd3d291010bd_onPageShow(e,obj,index){
   for (i = 1; i <= 10; i++) {
  }

}

Table variable(array) in list,
Any code block within "do" statement
In for each repeater, it will execute till the given list length. It will also give each list value to a variable.




var j;


function er_3eff8d47_6dd5_4f07_92d0_fd3d291010bd_onPageShow(e,obj,index){
   var j_list = [];
  for (var j_index in j_list) {
    j = j_list[j_index];
  }

}

Repeater Block

The Repeater block is used to execute the "do" statement block for a selective number of times. They can be used within the For and While loops.

InputOutputBlock LayoutGenerated Code

Variable or Number

The repeater statement.


The repeater will execute the given statement for a fixed number of times.Repeater
async function er_1673435223_click(e,obj,index){
   for (var count = 0; count < 10; count++) {
  }

}

Break or Continue Block

The Break statement is used to jump out of a loop. It can be used within any of the loops. (Mostly Break and Continue statements are used within While Loops)

The Continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop. 

InputOutputBlock LayoutGenerated Code
NAIt will break out of the repeater or continue to the next iteration.


for (i = 10; i >= 1; i--) {

  break;

}

for (i = 10; i >= 1; i--) {

  continue;

}

 


Was this article helpful?

What's Next
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence