When you use the Get current date and time action, the result is usually a date time variable stored in %CurrentDateTime%. It has various properties, using which allows you to retrieve parts of the date, such as the month, the day, the hour, etc. So, you can do an If statement to check if %CurrentDateTime.Hour% is greater than or equal to 17 (5PM) and then use Exit loop to stop looping when that's true.
It would look somewhat like this:

Make sure your Get current date and time action is inside the loop, so that you actually get an updated timestamp, and not just keep checking the same value over and over again.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.