• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Understanding a repeat loop (strings/characters)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Understanding a repeat loop (strings/characters)


  • Subject: Re: Understanding a repeat loop (strings/characters)
  • From: Paul Skinner <email@hidden>
  • Date: Sat, 22 Feb 2003 16:22:51 -0500

On Saturday, February 22, 2003, at 03:36 PM, Jeffrey Mattox wrote:

I'm trying to understand what is happening here:

set theString to (call method "getThing")
log (class of theString as string) -- "Unicode text"
repeat with theChar in theString
-- do things with each character
end repeat

The "repeat with" loops once for each character of theString, and that's what I want to happen. But, since theString is not a list, can somebody explain why the loop variable is fed each character rather than the entire string?

Jeff

Because your use of the 'repeat with foo in bar' structure implies that bar is a list that AS can repeat through. It's not; but certain data types can be coerced to a list; so AS does this silently.

It's more obvious in this example...

repeat with i in "abc"
say i as text
end repeat


Paul Skinner

Our earth is degenerate in these latter days; bribery and corruption are common; children no longer obey their parents; and the end of the world is evidently approaching.
-Assyrian clay tablet 2800 B.C. _______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: 
 >Understanding a repeat loop (strings/characters) (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: Understanding a repeat loop (strings/characters)
  • Next by Date: Re: newbie needs help batch filenaming
  • Previous by thread: Understanding a repeat loop (strings/characters)
  • Next by thread: Re: Understanding a repeat loop (strings/characters)
  • Index(es):
    • Date
    • Thread