Team LiB
Previous Section Next Section

B.7. Repeat Statements

Most repeat statements work the same way with either HyperTalk or AppleScript. There are a couple kinds of statements, however, that use slightly different syntax depending on the programming language you use.

For example, in HyperCard, some people insert the word for into their repeat statements, like this:

repeat for 10 times
    --Do things
end repeat

The fact is, the word for is unnecessary in HyperTalk. And in AppleScript, you're simply not allowed to use the word for in your repeat statements at all.

The other difference with repeat statements comes when you want to increment a variable each time your loop runs. In HyperTalk, you'd use the following syntax to increment a variable (theAge) from 10 to 20:

repeat with age=10 to 20
    --Each time this part runs, "age" will be one greater than before
end repeat

In AppleScript, the syntax is slightly different:

repeat with age from 10 to 20
    --Each time this part runs, "age" will be one greater than before
end repeat

    Team LiB
    Previous Section Next Section