Leaves a For Each command, Xfor Each command, Do While command or For To Step command.
Exit
Objects: Procedure, Work Panel, Web Panel, Panel
This command allows you to leave a For Each command, Xfor Each command, Do While command or For To Step command. The next command to be executed after an Exit, is the command following the EndFor, Xendfor, EndDo or EndFor corresponding to the For each, Xfor each, Do While or For group containing it.
Notes:
- The Exit command is not valid within a "For Each Line" group.
- The Exit does not work within a Do While when generated in Cobol for iSeries code.
In a system that handles Employee information, consider the following Transaction object:
Employee
{
EmployeeId*
EmployeeName
EmployeeDateOfBirth
EmployeeDateOfAdmission
EmployeeResignDate
....
}
Suppose you may want to know if an employee has quit within a specific period of time.
After verifying if there is at least one matching that condition, you want to exit the For each and stop the search.
The implementation would be:
&Found = 0
For each Employee order EmployeeResignDate
Where EmployeeResignDate >= &StartDate
Where EmployeeResignDate <= &EndDate
&Found = 1
Exit
EndFor
If &Found = 1
Msg('Employee found that satisfies the condition')
Else
Msg('NO Employee satisfies the condition')
EndIf
For Each command
Xfor Each command
Do While command
For To Step command