Break
Table of Contents
Overview
The break statement when executed terminates the execution of the current loop and resumes execution of the first statement after the loop. Typically, a break statement is used for an abrupt drop out from the current loop.
Syntax
break;
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.
This task can be used in the following events
When a record is Created | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Created or Edited | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Edited | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Deleted | ||
On Validate | Yes | |
On Success | Yes | |
Other workflow events | ||
On a scheduled date | Yes | |
During approval process | Yes | |
During payment process | Yes | |
In a Custom Function | Yes | |
In an Action item in report | Yes |
Example 1
The list - colors contains 4 values. In the following example, if the value "Red" is available in the list, the execution of the for loop will be terminated.
colors = List(); colors.add("Green"); colors.add("Red"); colors.add("Blue"); colors.add("Teal"); for each rec in colors { if(rec == "Red") { break; } info rec; }
Returns:
Green
Example 2
Let's assume a collection variable - technicians contains details of different technicians and their availability statuses. To display the first available technician, you can use "break" statement.
technician1 = Collection(); technician1.insert("name":"Alberto"); technician1.insert("status":"unavailable"); technician2 = Collection(); technician2.insert("name":"Bruno"); technician2.insert("status":"available"); technician3 = Collection(); technician3.insert("name":"A3"); technician3.insert("status":"available"); technicians = Collection(); technicians.insert(technician1); technicians.insert(technician2); technicians.insert(technician3); for each technician in technicians { if(technician.get("status") == "available") { info technician.get("name") + " is available"; break; } } //Returns Bruno is available