Table of Contents


The break statement terminates execution of current loop and resumes execution from the next statement after the loop. Typically, break statement is used for an abrupt drop out from the current loop.



The syntax can be placed within a conditional block. When the condition is met, the current loop is terminated and the immediate next statement after the loop takes the control.


Example 1

In the following example, "li" is a list containing colours "Blue", "Green" and "Red". While iterating through the list, when "Green" is found, the current loop is terminated and the next statement(after the loop) starts getting executed. When the loop gets terminated, "rec" contains only colour "Blue".

li = List();
for each rec in li
if(rec == "Green")
info rec;

Example 2

Let us say we have an application in which we need to send an email to owners of "pending" orders. In such cases, break statement can be used to halt the iteration as soon as the condition meets and to perform further action such a sending a mail etc.

for each record in Orders
if(Order_Status == "Pending")
from: <enter an email ID or valid zoho variable>
to: <enter an email ID or valid zoho variable>
subject: <Enter a Subject>
message: <Enter your message>

In this case, as soon as "Pending" Order is found, an email is sent to the contact and the iteration is stopped.

Share this post : FacebookTwitter