March 2019
Beginner to intermediate
324 pages
7h 17m
English
In Go, there is a single keyword that you can use when you want to write a loop—for. There are no other keywords to indicate a loop in Go.
Let's look at the following code. Let's say we want to loop from 1 to 10; here is how this is done:
for i:=1;i<=10;i++{//do something with i}
As in other languages, your for statement needs to include the following:
What if we have a slice or an array and we want to iterate over it in a loop? Go comes to the rescue with the concept of for .. range. Let's assume we have a slice called myslice and that we want to iterate over it. Here is what ...
Read now
Unlock full access