Nested If Statement

...

Go Nested if Statement

if bayonotlarini ichma-ich joylashtirish mumkin, buni nested if (ichma-ich if) deb ataladi.

Sintaksis

if condition1 {
   // condition1 haqiqiy bo'lsa bajariladigan kod
  if condition2 {
     // condition1 va condition2 ikkalasi ham haqiqiy bo'lsa bajariladigan kod
  }
}

Misol

Bu misol ichma-ich if bayonotlarini qanday ishlatishni ko'rsatadi:

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.

Ushbu sahifada

Xato haqida xabar berish