Ichma-ich if
Ichma-ich if operatori
if operatorlari ichida if operatorlari bo‘lishi mumkin, bu ichma-ich if (nested if) deb ataladi.
Sintaksis
if condition1 {
// code to be executed if condition1 is true
if condition2 {
// code to be executed if both condition1 and condition2 are true
}
}
Misol
Ushbu misolda ichma-ich if operatorlaridan qanday foydalanish ko‘rsatilgan:
package main
import "fmt"
func main() {
num := 20
if num >= 10 {
fmt.Println("Num is more than 10.")
if num > 15 {
fmt.Println("Num is also more than 15.")
}
} else {
fmt.Println("Num is less than 10.")
}
}
Natija:
Num is more than 10.
Num is also more than 15.
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
