Home THE HYPERCARD CENTER

HyperTalk Reference
Home » HyperTalk Reference » Keywords

Note: This is a work in progress and will be formatting errors. Read more about the project on the home page.

if (multiple-statement)

if trueOrFalse then
    statements
[else if trueOrFalse then
   statements]
[else
    statements]
end if


The multiple-statement if structure tests the specified condition and executes one or more statements if the condition is true. You use the optional else if or else form to run alternative blocks of code in case the condition following if is false.


Because each part of a complex if structure may contain more than one statement, you must have an end if statement at the end of the structure.


Demo Script

on mouseUp
  put random(19) into theNumber
  put 0 into botNum
  put 20 into topNum
  put 0 into numberOfTrys
  put "I am thinking of a number between 0 and 20." & return & ¬
  "Try to guess the number:" into sayIt
  repeat
    add 1 to numberOfTrys
    ask sayIt
    if the result is "Cancel" OR it is empty then exit repeat
    put it into theGuess
    if theGuess = theNumber then
      answer "You got it! The number is" && theGuess & "." & return &¬
      "You guessed in" && numberOfTrys && "attempts."
      exit repeat
    else if theGuess is not a number then
     put theGuess && "is not a number." into sayIt
    else if theGuess > topNum then
      put theGuess && "is greater than" && topNum & "." into sayIt
    else if theGuess < botNum then
      put theGuess && "is less than" && botNum & "." into sayIt
    else if theGuess < theNumber then
      put "The number is greater than" && theGuess & "." into sayIt
      put theGuess into botNum
    else if theGuess > theNumber then
      put "The number is less than" && theGuess & "." into sayIt
      put theGuess into topNum
    end if
    put return & "Please enter a number between" && botNum &&¬
    "and" && topNum & ":" after sayIt
  end repeat
end mouseUp

Placeholders

trueOrFalse
Any expression that evaluates to the HyperTalk and AppleScript constants true or false.

For example:

true
false
the hilite of bg btn "Yes"
fld "Zip" contains "95014"
the short name of this stack is "Fred"


statements
Any return-separated list of built-in commands, user-defined handlers, or keywords that are part of a message or function handler.

put "Hello world"   -- built-in command
get total(field 1)  -- function call
global HelpInfo     -- keyword


Related Topics

« global | HyperTalk Reference | if (single-statement) »


Version 0.7b1 (March 24, 2022)

Made with Macintosh

Switch to Modern View

Home
The HyperCard Center
HyperTalk Reference
Home » HyperTalk Reference » Keywords

Note: This is a work in progress and will be formatting errors. Read more about the project on the home page.

if (multiple-statement)

if trueOrFalse then
    statements
[else if trueOrFalse then
   statements]
[else
    statements]
end if


The multiple-statement if structure tests the specified condition and executes one or more statements if the condition is true. You use the optional else if or else form to run alternative blocks of code in case the condition following if is false.


Because each part of a complex if structure may contain more than one statement, you must have an end if statement at the end of the structure.


Demo Script

on mouseUp
  put random(19) into theNumber
  put 0 into botNum
  put 20 into topNum
  put 0 into numberOfTrys
  put "I am thinking of a number between 0 and 20." & return & ¬
  "Try to guess the number:" into sayIt
  repeat
    add 1 to numberOfTrys
    ask sayIt
    if the result is "Cancel" OR it is empty then exit repeat
    put it into theGuess
    if theGuess = theNumber then
      answer "You got it! The number is" && theGuess & "." & return &¬
      "You guessed in" && numberOfTrys && "attempts."
      exit repeat
    else if theGuess is not a number then
     put theGuess && "is not a number." into sayIt
    else if theGuess > topNum then
      put theGuess && "is greater than" && topNum & "." into sayIt
    else if theGuess < botNum then
      put theGuess && "is less than" && botNum & "." into sayIt
    else if theGuess < theNumber then
      put "The number is greater than" && theGuess & "." into sayIt
      put theGuess into botNum
    else if theGuess > theNumber then
      put "The number is less than" && theGuess & "." into sayIt
      put theGuess into topNum
    end if
    put return & "Please enter a number between" && botNum &&¬
    "and" && topNum & ":" after sayIt
  end repeat
end mouseUp

Placeholders

trueOrFalse
Any expression that evaluates to the HyperTalk and AppleScript constants true or false.

For example:

true
false
the hilite of bg btn "Yes"
fld "Zip" contains "95014"
the short name of this stack is "Fred"


statements
Any return-separated list of built-in commands, user-defined handlers, or keywords that are part of a message or function handler.

put "Hello world"   -- built-in command
get total(field 1)  -- function call
global HelpInfo     -- keyword


Related Topics

« global | HyperTalk Reference | if (single-statement) »

Version 0.7b1 (March 24, 2022)

Made with Macintosh

Switch to Retro View