>  기사  >  백엔드 개발  >  GO 학습 : - 루프

GO 학습 : - 루프

Patricia Arquette
Patricia Arquette원래의
2024-10-15 12:06:52482검색

Learning GO : - Loops

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

Loops

  • In Go lang there is only for loop , other than this there are no loops

  • So, same as conditionals, loops does not have round brackets to wrap around the condition

    for i := 0; i < 200; i++ {}
  • they are directly declared with the := syntax for the variable declaration

Infinite for Loop

  • if we define a for loop without any condition then that loop can work as an infinite loop
    for {
        fmt.Println("===============")
        fmt.Println("What do you want to do?")
    }
  • one way to get out of the infinite loop in this case would be to use return statement but with that whole program will be stopped and anything added after that will not be executed

  • So to get out of the loops we can use the break statement, which will stop the loop and start executing next line of the loop

  • We can use continue statement to break out of any particular condition and get back to the main loops, this helps when working with conditions inside a loop, so that way we can stop any particular condition and start the loops again

  • continue statement will stop the current iteration of the loop and start again that loop

Switch statement

  • It is same as the other languages, nothing specific to GO in this
switch choice {
        case 1:
            fmt.Println("Your Balance is", accountBalance)
        case 2:
            fmt.Print("Your Deposit: ")
        case 3:
            fmt.Print("Withdrawal Amount:")
        default:
            fmt.Print("Goodbye!")
        }

위 내용은 GO 학습 : - 루프의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.