web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Nested loop only runs ...
Power Automate
Unanswered

Nested loop only runs on first iteration

(1) ShareShare
ReportReport
Posted on by 6

EDIT: I believe I have found the problem: I am not resetting "Class Time" back to the beginning of the day at the end of the inner "While" loop. Fixed that and everything is running correctly, going on to the next day like it should. Thanks @NathanAlvares24 for having me actually inspect the variables rather than assuming everything was kosher.

 

I have the below While loop within a For loop. The flow runs through the If/Else statements, then runs the inner While loop the first time until the condition is met, then runs the if/else again for the remaining six times of the For loop, without dropping back into the nested While loop. What have I missed? 

 

rgreenstreet_0-1719957187966.png

rgreenstreet_1-1719957447380.png

 

I have the same question (0)
  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @rgreenstreet !

     

    Can you put a breakpoint here given in red in the pic:

    NathanAlvares24_0-1719979320733.png

     

    And take a screenshot of the output of the flow variables. Mostly want the variables, ClassTime and LastClassTime.

    I can see here at least the LastClassTime will have some data as seen below:

    NathanAlvares24_1-1719979429438.png

     

    But where is your variable, ClassTime? Is it initialized before entering this Main loop (DayOfWeekNumber) or is it initialized after the while condition?

     

    Also take a screenshot of the same flow variables after it has finished one while loop. I think your variable, ClassTime is not getting changed within the while loop.

     

    Please do provide more info of the same. We will surely guide you.

  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    @rgreenstreet 

     

    And also I can see that you are checking the time in that while condition. But those variables are storing some hardcoded values which by default will store as text. You can use the "convert text to datetime" action and then let those variables go into the while loop. Also make the ClassTime variable gets updated within the while loop otherwise you will end up in an infinite loop. See below:

     

    NathanAlvares24_2-1719980529273.png

    Note:

    hh:mm tt - this is for 12 hour format

    HH:mm tt - this is for 24 hour format

     

    Make sure your LastClassTime and ClassTime follow the necessary format as I can see in the LastClassTime variable as seen below:

     

    NathanAlvares24_3-1719980706453.png

    It shows "8:00 PM" which does not match the standard format I gave you. Try adjusting it to "08:00 PM". And it will work.

  • rgreenstreet Profile Picture
    6 on at

    @NathanAlvares24 Thank you for your help! Attached is a screenshot of the whole flow together. Ignore the breakpoint on line 7, I accidentally put it there before taking the screenshot.

     

    Regarding the time format for "ClassTime", It has to end up as text, because it's going to be input into a text field using emulated typing, rather than an actual datetime field. It gets converted to datetime where necessary for math, but regardless, that particular variable value doesn't seem to be the issue, because like I said originally, the "While" loop runs enough times to create classes for each hour of that day, and it changes the class time each time, it just doesn't start back over for the next day. 

     

    Here are the variables before entering the loop for the first time:

    rgreenstreet_0-1720466615610.png

    I haven't been able to actually make it through the "While" loop again this time around because the "click link on web page" action keeps breaking and not being able to find the element by its ID, but that's a different issue. Because of that, I don't have the values of the variables after the first time through scheduling for a day.

     

    Thanks again for your help

     

     

     

     

    combined.png
  • rgreenstreet Profile Picture
    6 on at

    I was able to get it through the first day's loop, here are the variables going back into the outer loop:

    rgreenstreet_0-1720467841455.png

    After this it goes through the "If" statements and completely skips the "while" loop and starts the outer loop back over again

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 481

#2
11manish Profile Picture

11manish 278

#3
David_MA Profile Picture

David_MA 276 Super User 2026 Season 1

Last 30 days Overall leaderboard