Re: loops
Re: loops
- Subject: Re: loops
- From: "Marc K. Myers" <email@hidden>
- Date: Thu, 14 Feb 2002 12:09:38 -0700
- Organization: [very little]
>
Date: Thu, 14 Feb 2002 10:07:32 +0000
>
From: Jason Davies <email@hidden>
>
Subject: loops
>
To: AppleScript Users <email@hidden>
>
>
can someone explain loops to me? I see them here, I see them there, I see them
>
in my O'Reilly Applescripting book, I even use them when other people write them
>
for me...
>
>
but I do not understand how they work and therefore cannot write my own without
>
worrying.
>
>
The examples I see are usually ( I quote from the veritable BBedit 6.0 manual)
>
>
repeat with i in every line of document 1
>
--do stuff here
>
end repeat
>
>
what is 'i'? Why should that have anything to do with repeats? Is it just a
>
character? is it a Roman '1'? does it matter? I cannot seem to find an answer to
>
this...!
A loop is a logical structure that allows the same action to be
performed on a number of data elements. The form of repeat statement
you're showing here will successively set i to each line in document 1
and allow you to do something to it. The i is a "loop variable". Each
time through the repeat it will contain a different line from the
document. Programmers often abbreviate frequently used variables to a
single character to avoid a lot of keystrokes, hence the "i". It would
be clearer if more descriptive variable names were used and would work
exactly the same way:
set theLines to (every line of document 1)
repeat with aLine in theLines
--do something here
end repeat
The "every line of document 1" is a reference form that returns a list,
each item of which is a line.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[02/14/2002 12:07:15 PM]
_______________________________________________
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.