sindresorhus / Actions

⚙️ Supercharge your shortcuts
https://sindresorhus.com/actions
2.68k stars 115 forks source link

Action proposal: While Loop #138

Closed hutonahill closed 9 months ago

hutonahill commented 1 year ago

Description

The title speaks for itself. I don't even know if this is possible, but it would be amazing.

jsiegenthaler commented 1 year ago

A while loop already exists (REPEAT) but it is limited to fixed number of iterations or iterating all items in a list. I think what would be really useful would be a while loop with a customizable exit condition: WHILE x < y, where it checks the values at each iteration, allowing you to break a loop early if needed. Alternatively a BREAK command to exit an existing REPEAT loop would be just as useful.

hutonahill commented 1 year ago

REPEAT is a lot closer to a for loop than a while loop. Being able to loop until a condition has been met is what I am looking for. a BREAK function would technically work, but I can just see my professors lecturing me to dust if they heard I was using break.

jsiegenthaler commented 1 year ago

Let the professors lecture away. If you need to write code in language X, you are always limited to the available commands in that language. You can achieve what you want in Shortcuts using REPEAT and a nested shortcut structure. Shortcut A calls shortcut B. Shortcut B contains the loop, with an IF action inside the loop. Shortcut B can thus break the loop and return a value to shortcut A when the condition is met.

sindresorhus commented 9 months ago

I unfortunately don't think this is possible.

I encourage you to send feedback to Apple about making an action for this: https://feedbackassistant.apple.com

hutonahill commented 9 months ago

https://feedbackassistant.apple.com

Link doesn't work.