9.13. Swift if…else if…else statement

发布时间 : 2025-10-25 13:33:46 UTC      

Page Views: 9 views

One if statement can be followed by an optional else if...else statement else if...else statement is useful when testing multiple conditional statements.

When using statements such as if , else if , and else , you need to pay attention to the following points:

  • if there can be 0 or 1 after the statement else . But if there is else if statement else statement needs to be specified in the else if statement.

  • if statement can be followed by 0 or more else if statement elseif statement must be in the else before the statement appears.

  • Once if statement executed successfully, others else if or else statements are not executed.

9.13.1. Grammar #

if boolean_expression_1 { /* If boolean_ Expression_1 expression is true, execute the statement */ } else if boolean_expression_2 { /* If boolean_ Expression_2 expression is true, execute the statement */ } else if boolean_expression_3 { /* If boolean_ Expression_3 expression is true, execute the statement */ } else { /* If none of the above conditional expressions are true, execute the statement */ } 

9.13.2. Example #

import Cocoa var varA:Int = 100; /*Detect Boolean conditions*/ If varA==20{ /*If the condition is true, execute the following statement*/ Print ("The value of varA is 20"); }Else if varA==50{ /*If the condition is true, execute the following statement*/ Print ("The value of varA is 50"); }Else{ /*If all the above conditions are false, execute the following statement*/ Print ("no matching criteria"); } Print ("The value of the varA variable is (varA)"); 

When the above code is compiled and executed, it produces the following results:

No matching criteria The value of the varA variable is 100 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。