I'm not aware how to implement such WHILE-construction by only using Rules. However, if you also enable the Conditional Rules module, you can implement such WHILE-construction.
Example
Consider this rule (in Rules export format):
{ "rules_execute_a_while_loop" : {
"LABEL" : "Execute a while loop",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_conditional" ],
"ON" : { "node_insert" : [], "node_update" : [] },
"IF" : [
{ "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } },
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_free_format_nr" } }
],
"DO" : [
{ "drupal_message" : { "message" : "Value specified for \u0022Free format nr\u0022 is: [node:field-free-format-nr]" } },
{ "variable_add" : {
"USING" : { "type" : "integer", "value" : "1" },
"PROVIDE" : { "variable_added" : { "loop_counter" : "Loop counter" } }
}
},
{
"WHILE" : { "NOT data_is" : {
"data" : [ "loop-counter" ],
"op" : "\u003E",
"value" : [ "node:field-free-format-nr" ]
}
},
"DO" : [
{ "drupal_message" : { "message" : "Do your thing for \u0022loop_counter\u0022 value = [loop-counter:value]" } },
{ "data_calc" : {
"USING" : { "input_1" : [ "loop-counter" ], "op" : "+", "input_2" : "1" },
"PROVIDE" : { "result" : { "incremented_counter" : "Incremented counter" } }
}
},
{ "data_set" : { "data" : [ "loop-counter" ], "value" : [ "incremented-counter" ] } }
]
}
]
}
}
Some more details about this rule:
- Rules Events: After creating a new node, or after updating an existing node.
- Rules Conditions:
- Content is of type "Article".
- Entity has field, for field with machine name
field_free_format_nr
(which is of type integer
).
The above Rules Events and/or Rules Conditions can be more or less anything (I just used some of the popular ones). The actual magic is in the Rules Actions:
BTW, it could well be that the last 2 Rules Actions can be consolidates in a single one, though using 2 Rules Actions should be easier to understand what's happening.
Demo
With the above rule enabled, these are the messages shown if I create or update an article, and specify a value of 3
for the field_free_format_nr
field:
Value specified for "Free format nr" is: 3
Do your thing for "loop_counter" value = 1
Do your thing for "loop_counter" value = 2
Do your thing for "loop_counter" value = 3