{"identifier":26404,"topic":"Keywords","name":"if (multiple-statement)","text":"<code><pre>if <i>trueOrFalse<\/i> then \n   <i>statements<\/i> \n<\/pre><\/code>\n[<code>else if <i>trueOrFalse<\/i> then<\/code>  <code>   <i>statements<\/i><\/code> ] [<code>else    <i>statements<\/i><\/code> ] <code><pre>end if\n<\/pre><\/code>\nThe multiple-statement<code> if <\/code>structure tests the specified condition and executes <b>one or more<\/b> statements if the condition is true. You use the optional<code> else if <\/code>or<code> else <\/code>form to run alternative blocks of code in case the  condition following<code> if <\/code>is false. <br>\n<br>\n Because each part of a complex<code> if <\/code>structure may contain more than one statement, you must have an<code> end if <\/code>statement at the end of the structure. <br>\n","related":{"89783":"Comparison operators","90049":"Logical operators","6157":"Type and existence operators"},"examples":"","demo":"<code><pre>on mouseUp\n  put random(19) into theNumber\n  put 0 into botNum\n  put 20 into topNum\n  put 0 into numberOfTrys\n  put \"I am thinking of a number between 0 and 20.\" & return & \u00ac\n  \"Try to guess the number:\" into sayIt\n  repeat\n    add 1 to numberOfTrys\n    ask sayIt\n    <b>if<\/b> the result is \"Cancel\" OR it is empty then exit repeat\n    put it into theGuess\n    <b>if<\/b> theGuess = theNumber then\n      answer \"You got it! The number is\" && theGuess & \".\" & return &\u00ac\n      \"You guessed in\" && numberOfTrys && \"attempts.\"\n      exit repeat\n    <b>else if<\/b> theGuess is not a number then\n     put theGuess && \"is not a number.\" into sayIt\n    <b>else<\/b> <b>if<\/b> theGuess > topNum then\n      put theGuess && \"is greater than\" && topNum & \".\" into sayIt\n    <b>else<\/b> <b>if<\/b> theGuess < botNum then\n      put theGuess && \"is less than\" && botNum & \".\" into sayIt\n    <b>else<\/b> <b>if<\/b> theGuess < theNumber then\n      put \"The number is greater than\" && theGuess & \".\" into sayIt\n      put theGuess into botNum\n    <b>else<\/b> <b>if<\/b> theGuess > theNumber then\n      put \"The number is less than\" && theGuess & \".\" into sayIt\n      put theGuess into topNum\n    <b>end<\/b> <b>if\n<\/b>    put return & \"Please enter a number between\" && botNum &&\u00ac\n    \"and\" && topNum & \":\" after sayIt\n  end repeat\nend mouseUp<\/pre><\/code>\n ","debug":{"9":["if trueOrFalse then "],"10":["\rBecause each part o"]}}