首頁 > 後端開發 > Golang > 學習GO:06

學習GO:06

Patricia Arquette
發布: 2024-10-06 16:08:31
原創
198 人瀏覽過

Learning GO: 06

Hey! I am Currently learning Go Lang, and I am taking some basic Notes on my Notion and though I'd also just publish them here. They are not well thought out or well written but it's just me taking notes from time to time for my reference.

I am taking the Udemy Course by Maximilian Schwarzmüller,


Notes

Different way to declare return Variables

  • when you declare the type of variables on function, there you can also add the variables name, and that way you dont have to declare those return variables
  • also then you dont have to add those variable names after the return statement, Go will understand which variables to return

func calculateFutureValue(investmentAmount, expectedReturn, years float64) (fv float64, rfv float64) {
    fv = (investmentAmount) * math.Pow(1+expectedReturn/100, float64(years))
    rfv = fv / math.Pow(1+inflationRate/100, years)
    return
}


登入後複製
  • starting new project with command

go mod init example.com/bank


登入後複製
  • Booleans for checks

wantsCheckBalance := choice == 1


登入後複製
  • if condition is similar but only round parenthesis is not used, directly the condition is used

    if choice == 1 || choice == 2 {
    } 


登入後複製
  • All the conditional && and || are also the same
  • to check the condition or compare we can use the double equals operator ==
  • else if is also the same as other language


    if choice == 1 {
        fmt.Println("Your Balance is", accountBalance)
    } else if choice == 2 {
  }


登入後複製
  • Increment operator works the same

accountBalance += depositAmount
//which equals to accountBalance = accountBalance + depositAmount


登入後複製

以上是學習GO:06的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板