第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

多次輸入檢查,如果條件不滿足,則重復(fù)

多次輸入檢查,如果條件不滿足,則重復(fù)

Go
蝴蝶刀刀 2022-08-09 20:33:58
我已經(jīng)在codereview.stackexchange上發(fā)布了這個,我認(rèn)為那里更合適,但沒有得到任何反饋,所以我把它發(fā)布在這里,那里可能有更多的觀眾。我使用此代碼進(jìn)行了一些輸入檢查。在任何失敗的檢查中,我需要再次要求正確的輸入。我使用并實現(xiàn)了這一點,他們似乎被程序員作為一個概念所不喜歡。labelsgoto如何在沒有標(biāo)簽/轉(zhuǎn)到的情況下達(dá)到相同的效果?我考慮過將所有這些代碼放在一個函數(shù)中并從內(nèi)部調(diào)用自己,但由于某種原因,它只重復(fù)了一次 - 沒有一直問是否一直得到錯誤的答案。// 0 exitsvar f float64var n intstartGame := func() {reception:    fmt.Println()    fmt.Print(`Give number (1-9): `)    _, err := fmt.Scan(&f)    // check letters or symbols    if err != nil {        fmt.Println("Letters or symbols not accepted")        goto reception    }    // exit    if f == 0 {        os.Exit(0)    }    // check for integers only    if f < 1 || f > 9 || f-math.Ceil(f) != 0 {        fmt.Println("Only integer numbers between 1-9 are accepted")        goto reception    }    n = int(f)    // check for empty cells    if myArray[n-1] == false {        fmt.Println("Empty cell", n)        goto reception    }}
查看完整描述

3 回答

?
慕桂英3389331

TA貢獻(xiàn)2036條經(jīng)驗 獲得超8個贊

作為使用循環(huán)的替代方法,您可以使其成為遞歸函數(shù)。我不知道當(dāng)你顯然嘗試這樣做時,你做了什么,但這應(yīng)該按預(yù)期工作。


func startGame() {

    var f float64

    fmt.Println()

    fmt.Print("Give number (1-9): ")

    _, err := fmt.Scan(&f)


    if err != nil {

        fmt.Println("Letters or symbols not accepted")

        startGame()

    }

    if f == 0 {

        os.Exit(0)

    }

    if f < 1 || f > 9 || f-math.Ceil(f) != 0 {

        fmt.Println("Only integer numbers between 1-9 are accepted")

        startGame()

    }

    n := int(f)

    if myArray[n-1] == false {

        fmt.Println("Empty cell", int(f))

        startGame()

    }

}


func main() {

    startGame()

    fmt.Println("good luck! bye.")

}


查看完整回答
反對 回復(fù) 2022-08-09
?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊

var f float64 = math.MaxFloat32

var n int

for ;f!=0; {

    fmt.Println()

    fmt.Print(`Give number (1-9): `)

    _, err := fmt.Scan(&f)

    // check letters or symbols

    if err != nil {

        fmt.Println("Letters or symbols not accepted")

        continue

    }

    // check for integers only

    if f < 1 || f > 9 || f-math.Ceil(f) != 0 {

        fmt.Println("Only integer numbers between 1-9 are accepted")

        continue

    }


    n = int(f)

    // check for empty cells

    if f > 0 && myArray[n-1] == false {

        fmt.Println("Empty cell", n)

    }

}

此外,上述所有條件也可以作為s?;蛘撸梢允褂谩袄^續(xù)”。else if


查看完整回答
反對 回復(fù) 2022-08-09
?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗 獲得超13個贊

只是使用,如果evrything是好的。喜歡這個:for {}continuebreak


    startGame := func() {

        for {

            fmt.Println()

            fmt.Print(`Give number (1-9): `)

            _, err := fmt.Scan(&f)


            // check letters or symbols

            if err != nil {

                fmt.Println("Letters or symbols not accepted")

                continue

            }


            // exit

            if f == 0 {

                os.Exit(0)

            }


            // check for integers only

            if f < 1 || f > 9 || f-math.Ceil(f) != 0 {

                fmt.Println("Only integer numbers between 1-9 are accepted")

                continue

            }


            if !true {

                fmt.Println("Empty cell", n)

                continue

            }

            break

        }

    }

    startGame()

    fmt.Println("good luck! bye.")


查看完整回答
反對 回復(fù) 2022-08-09
  • 3 回答
  • 0 關(guān)注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號