User Tools

Site Tools


do switch

The do switch statement is new in the X# language (but it was present also in the Vulcan.NET language).

It is more similar to the switch statement that C has.

Please look at this sample code:

method( cLanguage as string ) as string 
local cResult as string
do switch cLanguage
case "german"
  cResult := "Deutsch"
case "italian"
  cResult := "Italiano"
case "english"
  cResult := "English"
  cResult := "unspported language"
end switch

This statement is very efficient and fast, but much less flexible as the do case statement. For example, the compiler will give an error in this case:

case "german"
case "english"
case "german"

And also this will not work (compiler error also):

case cLanguage

because the value need to be a constant and not a variable. If you need more than one value, you can write as well:

do switch nValue
case 1
case 2
  System.Console.WriteLine( "nValue either 1 or 2" )
end switch
doswitch.txt · Last modified: 2018/08/20 04:06 by wolfgangriedmann