[Golang] How To Loop Data Using Golang

Looping in programming languages ​​is the process of repeating the execution of a block of code until the desired conditions are met.

If the desired conditions are not met, the looping process will be terminated using a break statement, etc.

In the GO programming language, the looping process uses a for statement. The following is the use of for in the GO language.

  1. Using FOR without additional conditions and statements

The code above is an example of using for without conditions and additional statements by displaying numbers 1 to 5.

For without conditions and additional statements

2. Using FOR with break statement

The code above is an example of using for with the addition of a break statement. If the number is more than 3, the looping process will be stopped using the break statement.

For with break statement

3. Using FOR with continue statement

The code above is an example of using for with the addition of a continue statement. If the mod 2 number is 0 then the looping process will be skipped and continue to the next process.

For with continue statement

4. Using FOR Range

The code above is an example of using for range. In the go programming language, the foreach statement is replaced by a for range. Where the data will be repeated based on the amount of data.

For with for range

5. Using FOR Nested

The code above is an example of for nested with data looping starting from the smallest.

For nested with data looping starting from the smallest

The code above is an example of for nested with data looping starting from the largest.

For nested with data looping starting from the largest

Finally, we already know the looping process in the go programming language. So that later we can apply it to the API or system that we will create.

--

--

--

All about go language

Recommended from Medium

Must-have Tool for Every Developer

Showing URL Preview in Flutter

Terraform Implementation framework for AWS

How To Create API With Golang (GIN) And MySQL- Part 1

Why I Have Been Using Notion

Getting ready for Xero’s refreshed app partner program!

The shift from Java to Kotlin

Use of Break, Continue and Pass in Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amiruddin Saddam

Amiruddin Saddam

Backend Engineer at Jamtangan.com And will always learn something new.

More from Medium

Go-Lang Hands-On| Part-3

Calling a containerized Golang function using RPC

An image depicting how RPC works

Creating Websocket Handshake with Golang from Scratch

Sorting Algorithms: Insertion Sort in Golang