Re: Inner loop accepts values ahead of natural sequence of actions - how can that be?
Re: Inner loop accepts values ahead of natural sequence of actions - how can that be?
- Subject: Re: Inner loop accepts values ahead of natural sequence of actions - how can that be?
- From: Yvan KOENIG <email@hidden>
- Date: Sat, 10 Jun 2017 17:16:53 +0200
> Le 10 juin 2017 à 13:30, ILJA SHEBALIN <email@hidden> a écrit :
>
> Hello,
>
> I'm recently trying to figure out a logic behind the design of a script which
> contains two nested loops. The script counts the number of repeating words of
> a text and puts the information in a list of records each containing a label
> storing the word's textual value and another label that stores the number of
> repetitions of the word in the text.
>
> The script:
>
>
> set the_text to "It was the best of times, it was the worst of times, it was
> the age of wisdom, it was the age of foolishness, it was the epoch of belief,
> it was the epoch of incredulity, it was the season of Light, it was the
> season of Darkness, it was the spring of hope, it was the winter of despair,
> we had everything before us, we had nothing before us, we were all going
> direct to Heaven, we were all going direct the other way—in short, the period
> was so far like the present period, that some of its noisiest authorities
> insisted on its being received, for good or for evil, in the superlative
> degree of comparison only."
>
>
> set word_list to every word of text of the_text
> set word_frequency_list to {}
> repeat with every_word_ref in word_list
> set the_current_word to contents of every_word_ref
>
> set word_info to missing value
> repeat with record_ref in word_frequency_list --THE QUESTIONABLE LOOP
> (word_frequency_list is a list that contains records). Its position is closer
> to the opening of the outer loop.
> if the_word of record_ref = the_current_word then
> set word_info to contents of record_ref
> #exit repeat -- I discovered it's redundant since the
> script does without it.
> end if
> end repeat
>
> if word_info = missing value then --word_info is a record
> set word_info to {the_word:the_current_word, the_count:1}
> set end of word_frequency_list to word_info
> else
> set the_count of word_info to (the_count of word_info) + 1
> end if
> end repeat
> get word_frequency_list
>
You're wrong.
The exit repeat instruction MUST be enabled.
If you enable it, the script will spare 740 pass in the loop.
I send you OFF LIST a comparison of the histories.
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) samedi 10 juin
2017 17:16:46
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden