Thursday, February 21, 2013
AppleScript doesn’t have a continue statement, but Tom Lokhorst shows Ray Robertson’s trick of simulating one using an extra loop and exit repeat (AppleScript’s equivalent of break).
Tags: applescript, programming
This continue omission frustrated me a while ago. I ran into a problem where GraphicConverter sometimes thew an error when reading IPTC data (that the UI accesses successfully).
Rather than using a second loop, I ended up solving the problem by setting a variable in my on error block for reading the IPTC data and then checking the value of that variable before trying to do anything with the IPTC data in the rest of my loop.
The Robertson trick seems like it's probably the cleaner solution in most cases, so it's nice to hear of it! (In fact, maybe I should see if I can refactor my code into separate functions that might make it easy to use the second loop/exit repeat trick.)
Comments RSS Feed
Mail (will not be published)