I'm using Conditional Rules module, there some conditions inside the loop I need to break out of. However, there's no action in rules for stopping/terminating the loop.

I tried a custom rules where I tried the following but it does not work:

function my_module_break_rules_loop() {
  return FALSE;
function my_module_break_rules_loop() {
  return 0;
function my_module_break_rules_loop() {

The break works but display with this error message:

PHP Fatal error: Cannot break/continue 1 level in

Any one know how to stop/terminate the loop?


2 Answers 2


Install Conditional Rules so that you can add "conditions" between " rule actions". After that you can create a variable which iterates and use that to stop after the third elements.

  • can you include a sample rule (in export format) that demonstrates your answer? Jul 23, 2017 at 6:27

You ought to filter the array before handling it over to the foreach. You could do this by implementing a rule component that takes two parameters:

  1. The new (filtered) list.
  2. The item you are considering.

Put this component within a foreach loop. That would likely be another component.

If the parameter meets your criteria, then append it to the list. If not, do nothing. The result is that you then have your filtered list.

Now you can do your foreach.

Another possibility is to put a rule component within your loop that only runs if some passed in function works. Basically, a while loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.