• 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: if-else statements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: if-else statements


  • Subject: Re: if-else statements
  • From: Jon Pugh via AppleScript-Users <email@hidden>
  • Date: Sun, 24 Nov 2019 12:11:02 -0800

The crux is that using the shorthand form:

if [expression] then [statement]

does not allow an “else" clause or an "end if”.  If you want an “else" clause,
you need to not follow the “then” with another statement, which is a shorthand
that allows a single statement instead of several statements followed by an
“else” or “end if".

if [expression] then
        [statements]
else
        [statements]
end if

> On Nov 24, 2019, at 11:00 AM, iKel via AppleScript-Users
> <email@hidden> wrote:
>
> Hi everyone,
> I am trying to learn how if-else statements work in AppleScript. When I run
> the script below I get "Expected end of line, etc. but found “else”.” It
> seems like a simple script but I get this error and just really trying to
> learn the mechanics of if-else statements in AS. I appreciate the help and
> insight!
>
> set the dialog_result to ¬
>       (choose from list {1, 2, 3, 7} ¬
>               with title ("Pick the lucky number"))
> if the dialog_result is {7} then display dialog ¬
>               "You win!" buttons {"OK"} default button {"OK"}
> else
>       set the unluckyNumber to the dialog_result
>       display dialog the unluckyNumber & " is an unlucky number."
> end if
>
> Kind regards,
> Kell
>
>
> Logic is the foundation of the certainty of all the knowledge we acquire.
> -Leonhard Euler
>
> Kellen Ruyle
> email@hidden <mailto:email@hidden>

 _______________________________________________
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

References: 
 >if-else statements (From: iKel via AppleScript-Users <email@hidden>)

  • Prev by Date: Re: if-else statements
  • Next by Date: Re: if-else statements
  • Previous by thread: Re: if-else statements
  • Next by thread: Re: if-else statements
  • Index(es):
    • Date
    • Thread