9.10. Swift conditional statement

发布时间 :2023-12-08 01:10:05 UTC      

A conditional statement executes the program through one or more conditions set, executing the specified statement when the condition is true, and when the condition is false executes another specified statement when the.

You can use the following figure to briefly understand the execution of conditional statements:

Image0

Swift provides the following types of conditional statements:

Cycle type

Description

For-in

Iterate through all the elements in a set, such as intervals represented by numbers, elements in an array, characters in a string.

For cycle

Used to repeat a series of statements until specific conditions are met, usually by increasing the value of the counter after each loop is completed.

While cycle

Run a series of statements that, if the condition is true, run repeatedly until the condition becomes false.

Repeat…while cycle

A similar while statement differs from a block of code that executes a loop before determining a loop condition.

9.10.1. ? : Operator #

We have explained the conditional operator in the previous chapter ? : ,can be used as a substitute If. Else statement. Its general form is as follows:

Exp1 ? Exp2 : Exp3;

Where Exp1, Exp2, and Exp3 are expressions. Please note the use and locationof colons.

? the value of the expression is determined by Exp1. If Exp1 is true, the value of Exp2 is calculated, and the result is the entire ? the value of the expression. If Exp1 is false, the value of Exp3 is calculated, and the result is the entire ? the value of the expression.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.