Inner Loop Not Working for Second Iteration of Outer Loop

Hi everyone,

I have an issue with nested loops in my workflow.

Setup:
I have an input folder in Google Drive with multiple images. My workflow:

  1. Loop Over Items (outer loop) - processes each image from Drive
  2. Analyze each image and generate style prompts
  3. Get style types from Google Sheets
  4. Loop Over Style Variations (inner loop) - creates different styled versions
  5. Generate and upload new images

Problem:

  • First image: Everything works perfectly :white_check_mark: - all style variations are created
  • Second image: The inner loop (Loop Over Style Variations) doesn’t execute :cross_mark:
  • Instead, it jumps directly back to Loop Over Items and marks as DONE
  • No processing happens for the second image

Current Settings:

  • Loop Over Items: batchSize: 1, reset: false
  • Loop Over Style Variations: batchSize: 1, reset: false

Question:
Why does the inner loop work for the first iteration but skip completely for the second iteration of the outer loop?

Any help would be appreciated! :folded_hands:

Hey @diagon hope all is good. Welcome to the community.

I think you could get away with no loops or with only one. I am not sure what style prompts and style types are, but here is what I tried, maybe it will give you an idea of how to get rid of loops:

This gets images and styles “in parallel”, then creates permutations of prompts and styles and then generates images based on permutations.

The point I am trying to make here is, most nodes can handle multiple items coming in and would loop over them. See this doc.

2 Likes

Thank you for respond but i fixed the problem different approach

Added this expression to control inner loop execution:
{{ $node['Loop Over Style Variations'].context["done"] }}

The inner loop’s state wasn’t resetting between outer loop iterations. This expression checks the loop’s completion state and ensures it runs fresh for each iteration.

Thanks for the parallel processing suggestion though - that’s definitely a more scalable approach for larger datasets!

Works perfectly now! :+1:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.