[4.5] - Breaking out of a loop

Posted by IramK on 10-Jul-2017 04:27


I have a loop and I would like to exit the loop once I have found a value with a particular status in the loop. How can we do this using the LOOP_BEGIN and LOOP_END scenario?

var hasOpen = false;



  hasOpen = true;
break; // doesn't work!! } {!#LOOP_END.R5707634} return hasOpen;



All Replies

Posted by Srinivas Panyala on 14-Jul-2017 04:16

HI Iram,

Currently, this is not supported. Please raise an enhancement request.

You can use Server API - rbv_api.selectQuery() to get the records and use JavaScript for loop to iterate the records with the break statement.



Posted by Mohammed Siraj on 18-Jul-2017 01:49

Another possible solution is to define the looping construct within a JS function. In the JS function, add a return statement on the break condition.


function  startLoop(){



                          return true; // condition to break



     return false;


//invoke function


Note: Loop template tokens in RB are pre-processed and a copy of embedded statements within a loop is added for each loop record with record specific values. This is done before the JS engine (browser  or server-side) interprets the JS code snippet. Hence, it is not considered as an optimal approach for a large number of records esp. for employing static checks. This is more suited for creating HTML markup for each loop record and other similar use-cases. As suggested by Srinivas above, leveraging API support will be more relevant for this requirement.

This thread is closed