One way to Create A Conditional Loop In AEM WorkFlow
1. Create a workflow variable - Example: loopcount
The value of the workflow variable is maintained throughout the workflow instance
2. Increment the variable using Set Variable Step - Example: loopcount=loopcount+1
Changes to variable values affect only the instance of the process in which the change occurs. For example, when a workflow is initiated and variable data changes, the changes affect only that instance of the workflow. The changes do not affect other instances of the workflow that were initiated previously or are initiated subsequently.
3. Add rule a definition in Goto Step to define the exit criteria - Example: loopcount<10
The Goto Step allows you to specify the next step in the workflow model to execute, dependent on the result of a routing expression.
You can use variables to define the routing expression using the expression editor. In this example, the Goto step specifies the Tester Process Step(i.e. Step before Or Split) as the next step if the value for the loocount variable is less than 10 thus creating a loop. If the loopcount increases to 11 the workflow will exit the loop and go to normal flow.