Logo

dev-resources.site

for different kinds of informations.

Learning GO: 07 - Loops

Published at
10/15/2024
Categories
go
notes
notion
learning
Author
gaurav444
Categories
4 categories in total
go
open
notes
open
notion
open
learning
open
Author
9 person written this
gaurav444
open
Learning GO: 07 - 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++ {}
Enter fullscreen mode Exit fullscreen mode
  • 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?")
    }
Enter fullscreen mode Exit fullscreen mode
  • 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!")
        }
Enter fullscreen mode Exit fullscreen mode
notes Article's
30 articles in total
Favicon
vim_notes
Favicon
2024
Favicon
Exploring Oracle 24D: A Deep Dive into Release Notes
Favicon
Combining Ghost and Quarto (The Lazy Way)
Favicon
Managing To Dos in recurring meetings, when there's no agreed upon tool
Favicon
Google Workspace Mail Management
Favicon
Google Workspace Security Part 2: SSO, API Access, Managing Connected Apps and the Alert Center
Favicon
Google Workspace Security Part 1: Common Security Settings and 2SV
Favicon
Managing Google Workspace Part 3: MDM Basics, Vault, Reporting and Domains
Favicon
Get 10th Class Math Notes (Matric Part 2) โ€“ Download Now for Free
Favicon
Managing Google Workspace Part 1: Core Services, Additional Services and Marketplace Apps
Favicon
Managing Google Workspace Part 2: Gmail, Calendar and Drive
Favicon
Learning GO : 09 - Packages
Favicon
Hopefully Helpful Notes, Best Practices, ...
Favicon
Learning GO : 08 - File Handling, Error Handling
Favicon
Learning GO: 07 - Loops
Favicon
Learning GO: 03 - User Input, Variable Declaration without initialization
Favicon
Learning GO: 02 - Variable Declaration
Favicon
Learning GO: 04 - Printing Strings
Favicon
Learning GO: 06 - Function return values, if condition
Favicon
Learning GO : 01 - Type Declaration
Favicon
Learning GO: 05 - Function Declaration
Favicon
Why Obsidian Falls Short as a Note-Taking Tool
Favicon
VS Code for Note-Taking
Favicon
Notes on The Every Computer Performance Book
Favicon
dossi is now open source
Favicon
Promises in JS(Personal notes)
Favicon
I switched from Notion to Obsidian
Favicon
Notes templates
Favicon
Cloud Computing - "It's MAGIC"!

Featured ones: