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.
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".
for each rec in li
if(rec == "Green")
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.
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.