Tuto WINDEV Mobile 25
Part 4: Programming concepts 87 The SWITCH statement This statement is used to evaluate an expression and to run a process for each possible expression value. The SWITCH statement is used according to the syntax below: SWITCH <Expression> CASE Value 1: Process 1... CASE Value 2: Process 2... ... CASE Value N: Process N... OTHER CASE Process ... END Example: The following code retrieves today’s date and displays a different message according to its value. A specific message is displayed for the 1st and for the 15th of the month. In the other cases, today’s date is displayed. D is Date D = Today() SWITCH D..Day // Checks the day of the date CASE 1: Info("We are the first day of the month") CASE 15: Info("We are the 15th of the month") OTHER CASE: Info("We are the: " + DateToString(D)) END Remarks : • If the code line "CASE 1:..." is run, the other code lines corresponding to the possible values are not run. • Several values can be grouped in the same case. The different values are separated by a comma. For example: Sub is int = 2 SWITCH Sub CASE 1,2: Info("Case 1 or 2") CASE 3: Info("Case 3") OTHER CASE: Info("Other case") END • Several code lines can be run during the process corresponding to a condition. In this case, the following syntax must be used: SWITCH <Expression> CASE Value 1: Process 1 - Code line 1... Process 1 - Code line 2... CASE Value N: Process N - Code line 1... Process N - Code line 2... END
Made with FlippingBook
RkJQdWJsaXNoZXIy NDQ0OA==