欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

if條件語(yǔ)句怎么在Go語(yǔ)言項(xiàng)目中使用

if條件語(yǔ)句怎么在Go語(yǔ)言項(xiàng)目中使用?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

淇縣ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

if語(yǔ)句
if語(yǔ)句包含一個(gè)布爾表達(dá)式后跟一個(gè)或多個(gè)語(yǔ)句。

語(yǔ)法
if語(yǔ)句在Go編程語(yǔ)言的語(yǔ)法是:

復(fù)制代碼 代碼如下:


if(boolean_expression)
{
   /* statement(s) will execute if the boolean expression is true */
}


如果布爾表達(dá)式的值為 true,那么if語(yǔ)句里面代碼塊將被執(zhí)行。如果if語(yǔ)句的結(jié)束(右大括號(hào)后)布爾表達(dá)式的值為false,那么語(yǔ)句之后第一行代碼會(huì)被執(zhí)行。

流程圖:

if條件語(yǔ)句怎么在Go語(yǔ)言項(xiàng)目中使用

例子:

復(fù)制代碼 代碼如下:


package main

import "fmt"

func main() {
   /* local variable definition */
   var a int = 10
 
   /* check the boolean condition using if statement */
   if( a < 20 ) {
       /* if condition is true then print the following */
       fmt.Printf("a is less than 20\n" )
   }
   fmt.Printf("value of a is : %d\n", a)
}

讓我們編譯和運(yùn)行上面的程序,這將產(chǎn)生以下結(jié)果:

a is less than 20;
value of a is : 10


if...else語(yǔ)句
if語(yǔ)句可以跟著一個(gè)可選的else語(yǔ)句,布爾表達(dá)式是假時(shí)它被執(zhí)行。

語(yǔ)法
在Go編程語(yǔ)言中的if ... else語(yǔ)句的語(yǔ)法是:

復(fù)制代碼 代碼如下:


if(boolean_expression)
{
   /* statement(s) will execute if the boolean expression is true */
}
else
{
  /* statement(s) will execute if the boolean expression is false */
}


如果布爾表達(dá)式的值為true,那么if代碼塊將被執(zhí)行,否則else代碼塊將被執(zhí)行。

流程圖:

if條件語(yǔ)句怎么在Go語(yǔ)言項(xiàng)目中使用

例子:

復(fù)制代碼 代碼如下:


package main

import "fmt"

func main() {
   /* local variable definition */
   var a int = 100;
 
   /* check the boolean condition */
   if( a < 20 ) {
       /* if condition is true then print the following */
       fmt.Printf("a is less than 20\n" );
   } else {
       /* if condition is false then print the following */
       fmt.Printf("a is not less than 20\n" );
   }
   fmt.Printf("value of a is : %d\n", a);

}

當(dāng)上述代碼被編譯和執(zhí)行時(shí),它產(chǎn)生了以下結(jié)果:

a is not less than 20;
value of a is : 100

 if...else if...else 語(yǔ)句
if語(yǔ)句可以跟著一個(gè)可選的else if ... else語(yǔ)句,這是非常有用的使用單個(gè) if...else if 語(yǔ)句聲明測(cè)試各種條件。

當(dāng)使用if , else if , else語(yǔ)句有幾點(diǎn)要記住使用:

if可以有零或一個(gè)else,它必須跟從else if后面。

一個(gè)if可以有零到個(gè)多else if并且它們必須在else之前。

一旦一個(gè)else if測(cè)試成功,其它任何剩余else if將不會(huì)被測(cè)試。

語(yǔ)法
if...else if...else在Go編程語(yǔ)言中語(yǔ)句的語(yǔ)法是:

復(fù)制代碼 代碼如下:


if(boolean_expression 1)
{
   /* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2)
{
   /* Executes when the boolean expression 2 is true */
}
else if( boolean_expression 3)
{
   /* Executes when the boolean expression 3 is true */
}
else
{
   /* executes when the none of the above condition is true */
}


例子:

復(fù)制代碼 代碼如下:


package main

import "fmt"

func main() {
   /* local variable definition */
   var a int = 100
 
   /* check the boolean condition */
   if( a == 10 ) {
       /* if condition is true then print the following */
       fmt.Printf("Value of a is 10\n" )
   } else if( a == 20 ) {
       /* if else if condition is true */
       fmt.Printf("Value of a is 20\n" )
   } else if( a == 30 ) {
       /* if else if condition is true  */
       fmt.Printf("Value of a is 30\n" )
   } else {
       /* if none of the conditions is true */
       fmt.Printf("None of the values is matching\n" )
   }
   fmt.Printf("Exact value of a is: %d\n", a )
}

讓我們編譯和運(yùn)行上面的程序,這將產(chǎn)生以下結(jié)果:

None of the values is matching
Exact value of a is: 100

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

新聞名稱:if條件語(yǔ)句怎么在Go語(yǔ)言項(xiàng)目中使用
本文URL:http://chinadenli.net/article16/gdocdg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站策劃、微信小程序ChatGPT、云服務(wù)器、外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司