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…


This content originally appeared on DEV Community and was authored by Gaurav Vala

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



This content originally appeared on DEV Community and was authored by Gaurav Vala


Print Share Comment Cite Upload Translate Updates
APA

Gaurav Vala | Sciencx (2024-10-06T06:21:23+00:00) Learning GO: 06. Retrieved from https://www.scien.cx/2024/10/06/learning-go-06/

MLA
" » Learning GO: 06." Gaurav Vala | Sciencx - Sunday October 6, 2024, https://www.scien.cx/2024/10/06/learning-go-06/
HARVARD
Gaurav Vala | Sciencx Sunday October 6, 2024 » Learning GO: 06., viewed ,<https://www.scien.cx/2024/10/06/learning-go-06/>
VANCOUVER
Gaurav Vala | Sciencx - » Learning GO: 06. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/06/learning-go-06/
CHICAGO
" » Learning GO: 06." Gaurav Vala | Sciencx - Accessed . https://www.scien.cx/2024/10/06/learning-go-06/
IEEE
" » Learning GO: 06." Gaurav Vala | Sciencx [Online]. Available: https://www.scien.cx/2024/10/06/learning-go-06/. [Accessed: ]
rf:citation
» Learning GO: 06 | Gaurav Vala | Sciencx | https://www.scien.cx/2024/10/06/learning-go-06/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.