• 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: compactness of expression question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compactness of expression question


  • Subject: Re: compactness of expression question
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 17 Jan 2002 13:24:23 -0800

On 1/17/02 12:51 PM, "billp" <email@hidden> wrote:

> Is there a more compact way I can express the following?:
>
> if ItemKind = "Characters" then
> global CharacterCount
> set CharacterCount to ItemCount
> else
> if ItemKind = "Words" then
> global WordCount
> set WordCount to ItemCount
> else
> if ItemKind = "Lines" then
> global LineCount
> set LineCount to ItemCount as integer
> else
> if ItemKind = "Paragraphs" then
> global ParagraphCount
> set ParagraphCount to ItemCount as integer
> else
> if ItemKind = "Tables" then
> global TableCount
> set TableCount to ItemCount
> end if
> end if
> end if
> end if
> end if
>

Use else if':


if ItemKind = "Characters" then
global CharacterCount
set CharacterCount to ItemCount
else
if ItemKind = "Words" then
global WordCount
set WordCount to ItemCount
else
if ItemKind = "Lines" then
global LineCount
set LineCount to ItemCount as integer
else
if ItemKind = "Paragraphs" then
global ParagraphCount
set ParagraphCount to ItemCount as integer
else
if ItemKind = "Tables" then
global TableCount
set TableCount to ItemCount
end if
end if
end if
end if
end if


if ItemKind = "Characters" then
global CharacterCount
set CharacterCount to ItemCount
else if ItemKind = "Words" then
global WordCount
set WordCount to ItemCount
else if ItemKind = "Lines" then
global LineCount
set LineCount to ItemCount as integer
else if ItemKind = "Paragraphs" then
global ParagraphCount
set ParagraphCount to ItemCount as integer
else if ItemKind = "Tables" then
global TableCount
set TableCount to ItemCount
end if


I've never made a global statement midway through a script rather than at
the top, but I believe that will work. (Otherwise you'd declare them all as
global at the top, then just define the one you need - not so good.) Any
particular reason not just to declare

global ItemCount

and then just do:

if {ItemKind} is in {"Lines", "Paragraphs"} then
set ItemCount to ItemCount as integer
end if

Or do you need all these different ItemCounts at once?

--
Paul Berkowitz


References: 
 >compactness of expression question (From: billp <email@hidden>)

  • Prev by Date: Re: compactness of expression question
  • Next by Date: Re: how to tell if a particular application is running?
  • Previous by thread: Re: compactness of expression question
  • Next by thread: Re: compactness of expression question
  • Index(es):
    • Date
    • Thread