Re: loops
Re: loops
- Subject: Re: loops
- From: garbanzito <email@hidden>
- Date: Thu, 14 Feb 2002 13:11:24 -0700
at 2002 02 14, 12:09 -0700, they whom i call Marc K. Myers wrote:
[...] 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:
hearty agreement with that!
though i'm sure i've done it myself, it's really poor
practice to litter teaching examples with meaningless
variable names, especially in a supposedly
"self-explanatory" language like AppleScript.
further, even in ancient programming practice, "i" would be
better understood if it held an integer value, rather than
text. i wonder how many people realize this shorthand is
derived from Fortran, where variable names starting with
i,j,k,l,m & n were implicitly integers.
set theLines to (every line of document 1)
repeat with aLine in theLines
there is a subtle but important point here, well known to
experienced AppleScripters, which makes Mark's example much
more efficient and less prone to error ...
when assigned to a variable outside the repeat, "every line"
is evaluated only once, where the original example would
evaluate it on each cycle of the loop. in the case of a
large document, Mark's approach would be much faster.
my only quibble (and i realize most people think this is
very personal), is that running words together dilutes the
effort at readability. i go to the effort to put underscores
between words (even in terse languages) within a variable
name (i'd use "the_lines" and "a_line").
--
steve harley email@hidden
_______________________________________________
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: | |
| >Re: loops (From: "Marc K. Myers" <email@hidden>) |