Blender 4.0 introduced Repeat Zones, however they represent a for loop without a way to break early. This means a while loop can't be implemented in Geonodes as: [not using Python as an example as idiomatically it doesn't provide a traditional for loop]
for (i=0; i<MAX; i++) {
// usual body of a while loop
if (condition) break;
}
What you can do instead is:
for (i=0; i<MAX; i++) {
if (condition) continue;
// usual body of a while loop
}
This however has a very significant performance problem: it doesn't scale; if only a small number of iterations is needed, the loop may be no-oping basically through its entire lifetime, e.g. if the condition is met at the 2nd execution of the loop's body, and MAX
equals a million, the loop will be "idle" (no-op) 99.9999% of the steps! In such case the execution will unnecessarily take at least 8 additional seconds! [I benchmarked using a simple test]
Even if you assign MAX
adequately to the same order of magnitude as the actual Iterations needed, you can waste 7 seconds if you guess a million and it finishes early after a little over 100k iterations.
Here's one example where the number of Iterations is unknown: Refining material assignment in Blender geometry nodes based on neighboring faces
So until proper while loops are implemented, I'm looking for the best workaround and posting my proposition below.