Go switch is very flexible, the expression does not have to be a constant or an integer, the execution of the process from top to bottom until a match is found, do not break;
VAR score =98var result Stringswitch SCORE/10 {case 9,10:result= "excellent" Case 8:result= "good" case 6,7:result= "pass" default: Result= "Failed"}
The expression after switch is not even required
VAR score =-1var result Stringswitch {case score<0:result= "negative" case score=0:result= "0" Case score>0:result= " Positive number "}
Lizi:
Package Mainimport ("Log") Import ("Github.com/lxn/walk"). "Github.com/lxn/walk/declarative") var le *walk. Lineeditvar sport,maths,english *walk. Radiobuttonfunc Main () {if _, err: = Mainwindow1.run (); Err! = nil {log. Fatal (Err)}log. Fatal (Bind ("enabledcb.checked"))}var mainwindow1=mainwindow{Title: "MainWindow", minsize:size{300, (+), layout:v box{}, Children:widget,}var widget=[]widget{LineEdit1, Radiobuttonsport, Radiobuttonmaths, Radiobuttonenglish, Pushbuttonok,}var lineedit1=lineedit{assignto: &le,}var radiobuttonsport=radiobutton{AssignTo: &sport, Tex T: "Sports department",}var radiobuttonmaths=radiobutton{assignto: &maths, Text: "Mathematics department",}var Radiobuttonenglish=radiobutt on{Assignto: &english, Text: "English Department",}var pushbuttonok=pushbutton{Text: "OK", Onclicked:ok_clicked,}func OK_Cl icked () {switch {case 中文版. Checked (): le. SetText ("English Department") Case sport. Checked (): le. SetText ("sports department") case maths. Checked (): le. SetText ("Mathematics department ")}}
RadioButton is a radio button that can be grouped,
Radiobuttongroup and Radiobuttongroupbox
Go Walk Tutorial-Process Control (switch)