Skip to Content
Beginning AppleScript®
book

Beginning AppleScript®

by Stephen G. Kochan
December 2004
Beginner
600 pages
13h 42m
English
Wrox
Content preview from Beginning AppleScript®

4.5. The repeat until statement

This form of the repeat statement is actually quite similar to the repeat while. Whereas the repeat while statement repeats execution of a set of statements while a condition is true, the repeat until repeats execution of a set of statements while a condition is false, or in other words, until it becomes true.

The general format of the repeat until statement is

repeat until Boolean-expression
    statement
    statement
    ...
end repeat

You could replace the repeat while from the second version of the triangular number program with the following equivalent:

repeat until validNumber
    ...
end repeat

And taking note of the inverted logic here, you could replace the repeat while from the final version of the triangular number program with the following:

repeat until tries > 3 or validNumber
    ...
end repeat

You've seen three different uses of the repeat statement to count to 10. Here's another example using the repeat until:

set n to 1
repeat until n > 10
    log n
    set n to n + 1
end repeat

As previously noted, you often have a choice of which form of the repeat statement to use to accomplish a given task. If you're going to execute a set of statements a specified number of times, the repeat...times is a logical choice. And if you need access to a variable that counts the repetition number along the way, the repeat with-from-to statement usually fits the bill.

In the following Try It Out, you write a simple guessing program and learn about a special command for generating ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Take Control of Your M-Series Mac

Take Control of Your M-Series Mac

Glenn Fleishman
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9780764574009Purchase book