Go dasturlash tili: if, for, va switchga misollari
if operatoriga oid misollar
// 1. Sonning musbat yoki manfiyligini tekshirishifnumber>0{fmt.Println("Musbat")}else{fmt.Println("Manfiy")}// 2. Juft yoki toq sonifnumber%2==0{fmt.Println("Juft")}else{fmt.Println("Toq")}// 3. Tenglikni tekshirishifa==b{fmt.Println("Teng")}// 4. Yoshi kattamiifage>=18{fmt.Println("Balog'atga yetgan")}else{fmt.Println("Hali balog'atga yetmagan")}// 5. Harorat sovuqmiiftemperature<0{fmt.Println("Sovuq")}// 6. Toifa aniqlashifscore>=90{fmt.Println("A")}elseifscore>=80{fmt.Println("B")}else{fmt.Println("C yoki past")}// 7. Oddiy if bilan massivdan qidirishiflen(array)>0{fmt.Println("Massiv bo'sh emas")}// 8. O'zgarmaslarni solishtirishifconstant1!=constant2{fmt.Println("O'zgarmaslar teng emas")}// 9. Foydalanuvchi tizimga kirganmiifisLoggedIn{fmt.Println("Tizimga kirilgan")}else{fmt.Println("Tizimga kirmagan")}// 10. Mantiqiy ififx>10&&y<20{fmt.Println("Shart bajarildi")}
for operatoriga oid misollar
// 1. Oddiy siklfori:=0;i<10;i++{fmt.Println(i)}// 2. Massivni aylanib chiqisharray:=[]int{1,2,3}for_,value:=rangearray{fmt.Println(value)}// 3. Sonlarni yig'indisini topishsum:=0fori:=1;i<=5;i++{sum+=i}fmt.Println(sum)// 4. Cheksiz siklfor{fmt.Println("Bu cheksiz sikl")break}// 5. Shartli siklcount:=0forcount<5{fmt.Println(count)count++}// 6. Massivning indekslari bilan ishlashfori:=rangearray{fmt.Println(i)}// 7. Qatorni aylantirishfor_,ch:=range"salom"{fmt.Printf("%c\n",ch)}// 8. Ikki o'lchovli massivmatrix:=[][]int{{1,2},{3,4}}for_,row:=rangematrix{for_,col:=rangerow{fmt.Println(col)}}// 9. Even raqamlarni chiqarishfori:=0;i<=10;i+=2{fmt.Println(i)}// 10. Continue operatorifori:=1;i<=5;i++{ifi==3{continue}fmt.Println(i)}
switch case operatoriga oid misollar
// 1. Foydalanuvchi darajasini aniqlashswitchuserLevel{case"admin":fmt.Println("Administrator")case"user":fmt.Println("Oddiy foydalanuvchi")default:fmt.Println("Noma'lum daraja")}// 2. Son juftmi yoki toqswitchnumber%2{case0:fmt.Println("Juft")default:fmt.Println("Toq")}// 3. Haroratni baholashswitch{casetemperature>30:fmt.Println("Issiq")casetemperature>0:fmt.Println("Iliq")default:fmt.Println("Sovuq")}// 4. Rang tanlashswitchcolor{case"qizil":fmt.Println("Rang qizil")case"yashil":fmt.Println("Rang yashil")default:fmt.Println("Noma'lum rang")}// 5. Haftaning kunlariswitchday{case1:fmt.Println("Dushanba")case7:fmt.Println("Yakshanba")default:fmt.Println("Boshqa kun")}// 6. Oddiy qiymat taqqoslashswitchx{case10:fmt.Println("x = 10")case20:fmt.Println("x = 20")default:fmt.Println("x noma'lum qiymatga teng")}// 7. Vaqt oralig'ini aniqlashswitch{casehour<12:fmt.Println("Ertalab")casehour<18:fmt.Println("Kunduzi")default:fmt.Println("Kechasi")}// 8. Ruxsatlarni tekshirishswitchhasPermission{casetrue:fmt.Println("Ruxsat bor")default:fmt.Println("Ruxsat yo'q")}// 9. Foydalanuvchi yoshiswitchage{case18:fmt.Println("Voyaga yetgan")case65:fmt.Println("Pensiya yoshi")default:fmt.Println("Oraliq yosh")}// 10. Numeratsiyani solishtirishswitchnumber{case1,2,3:fmt.Println("1 yoki 2 yoki 3")default:fmt.Println("Boshqa qiymat")}
if, for va switch case birgalikda ishlatilgan misollar