The sayHello function receives the names parameter as a slice. To iterate over a map in Golang, we use the for range loop. The first time we print the value of the slice integers, we see all zeros. That's going to be less efficient than just iterating over the three slices separately, especially if they're quite large. go. This problem is straightforward as stated (see PatrickMahomes2's answer ). It provides a doubly linked list implementation that allows for efficient insertion, deletion, and traversal operations. In Go programming, we can also create a slice from an existing array. 4. Share . You could either do a simple loop such as for d :=. Variables in Go (Golang) – Complete Guide. Body to json. Remainder Operator in Go. Split (photos, ", ") }. A nil slice declared as var s1 []string has no underlying data array - it points to nothing. There is no built in i'm aware of that lets you iterate over all the exported variables in a vars block. To declare a golang slice, use var keyword with variable name followed by []T where T denotes the type of elements that will be stored in the slice. 2. $ go version go version go1. Method-1: Using for loop with range keyword. 18. Share. You can use the %v verb as a general placeholder to convert the interface value to a string, regardless of its underlying type. ReadAll(resp. In the documentation for the package, you can read: {{range pipeline}} T1 {{end}} The value of the pipeline must be an array, slice, map, or channel. A slice is a flexible and extensible data structure to implement and manage collections of data. – Emanuele Fumagalli. It can be used here in the following ways: Example 1:When you need to store a lot of elements or iterate over elements and you want to be able to readily modify those elements, you’ll likely want to work with the slice data type. Which is the best procedure (easier to write and understand) to break this slice into 3 parts, for example, and distribute the content in three sub-slices? If I have: var my_sub_slice1 []string var my_sub_slice2 []string var my_sub_slice3 []stringWhat is the correct way to create a new slice in Golang? A) slice := make([]. There isn't a practical operator to solve this. View community ranking In the Top 1% of largest communities on Reddit. ReadAll returns a []byte, no need cast it in the next line; better yet, just pass the resp. One method to iterate the slice in reverse order is to use a channel to reverse a slice without duplicating it. for i := 0; i < len(s); i++ {, without causing index-out-of-bounds errors. or alternatively as: A major take away from processing lists this way is that if you chain File(), Map(), Reduce() this way the processing of the incoming data stream is done concurrently (thanks to the goroutines), therefore, it doesn’t wait: Filter() starts as the first data come in, Filter() also does not wait and starts as soon as the first ‘fibs’ come in,. Sort() does not) and returns a sort. Let’s see how to use range with some of the data structures we’ve already learned. nested range in Go template. 6. Idiomatic way of Go is to use a for loop. 1. With it static typing, it is a very simple and versatile programming language that is an excellent choice for beginners. ). If it is, you have a few options. But to be clear, this is most certainly a hack. Get all keys from map in Golang Template without use vars. Iterate Go map get index. c:= make ([] string, len (s)) copy (c, s) fmt. Loaded 0%. The range keyword is used to more easily iterate over an array, slice or map. I am trying to write a simple program that creates a struct called 'person' which accepts firstname, lastname, and age. The slice trick is useful in the case where a single element is deleted. type Person struct { ID int NAME string } Example of a slice of structs [{1 John},{2, Mary},{3, Steven},{4, Mike}] What I want in index. range loop construct. Also, each time you iterate on a map with range, you get a different order - another hint that there's no index concept in maps. 0. For each entry it assigns iteration values to corresponding iteration variables and then executes the block. The idiomatic way to iterate over a map in Go is by using the for. var bar = []string {} // empty slice fmt. Number of fields: 3 Field 1: Name (string) = Krunal Field 2: Rollno (int) = 30 Field 3: City (string) = Rajkot. When you change an element of a slice, you modify the corresponding element of its underlying array, and other slices that share the same underlying array will see the change. Reversing an array is fairly straightforward in Go, due to multiple return values. 2. 9. Mar 22, 2017. This problem is straightforward as stated (see PatrickMahomes2's answer ). The syntax to use AND Operator in Go language with operands x and y is. 1. Step 3 − To iterate through the dictionary's keys and produce a slice of the keys, initialize a for loop with the range keyword. )) to sort the slice in reverse order. GoBytes (cArray unsafe. Golang Slice; Golang – Slice Length; Golang – Iterate over Slice using For Loop; Golang – Check if Specific Element is present in Slice; Golang – Sort Slice of Strings; Golang – Sort Slice of Integers; Structures. First we can modify the GreetHumans function to use Generics and therefore not require any casting at all: func GreetHumans [T Human] (humans []T) { for _, h := range humans { fmt. The counter is set from 0 or any other starting value as the. At the basic level, reflection is just a mechanism to examine the type and value pair stored inside an interface variable. 2 Iterate over elements of a slice: for. Iterate on a golang array/slice without using for statement. I’m looking to iterate through an interfaces keys. How do I iterate through a Go slice 4 items at a time. References. To start, we need to ensure that the we're dealing with a slice by testing: reflect. If you want to reverse the slice with Go 1. Modifying a Go slice in-place while iterating over it. a six bytes large integer), you have to first extend the byte slices with leading zeros until it. if your structs do similar end result (returns int or operates on strings) but does so uniquely for each struct type you can define functions on them: The reflect package allows you to inspect the properties of values at runtime, including their type and value. The value of the pipeline must be an array, slice, map, or channel. Use the map Function to Implement a foreach Loop in Golang. To initialize the slice during declaration, use this: myslice := []int{1,2,3} The code above declares a slice of integers of length 3 and also the capacity of 3. Go range tutorial shows how to iterate over data structures in Golang. This will repeatedly receive values from the channel until it is closed. To declare a golang slice, use var keyword with variable name followed by []T where T denotes the type of elements that will be stored in the slice. When I'm following this golang blog post about arrays and slices, I tried to pass a pointer to a slice to a function that modify the underlying len property in the slice header: func PtrSubtractOneFromLength (slicePtr * []byte) { slice := *slicePtr *slicePtr = slice [0 : len (slice)-1] } And when I tried to refactor it to this from:So what I did is that I recursively iterated through the data and created an array of a custom type containing the data I need (name, description) for each entry so that I can use it for pagination. Scanner. Alternatively, you can use the “range construct” and range over an initialized empty slice of integers. If so, my guess as to why the output is exactly 0A, 1M, 2C, - because, originally, the slice was passed to the loop by pointer, and when the capacity of the slice is doubled in the first iteration of the loop, the print(i, s). The iteration values are assigned to the respective iteration variables, i and s , as in an assignment statement. Since there is no int48 type in Go (i. Println (fruits [i]) } } 2. Code. Explanation: In Golang, the ‘range’ keyword can be used to iterate over a slice, returning the index and the value at each iteration. below is the code I am trying:When you slice a slice, (e. Go’s rich standard library makes it easy to split a string into a slice. Sprintf("%s10", s) assigns to local variable s, which is discarded. version: "1" steps: - name: sample_test_latest commands: - go test . To do this, we have to manually implement the insert() method using the append() function. . . The following example uses range to iterate over a Go array. Pass full slice range as parameter. We want to print first and last names in sorted order by their first name. Embark on a journey through Golang slices, exploring their creation, manipulation, and efficient management in Go applications. For example, Suppose we have an array of numbers. It only checks the condition and runs if it matches. Firstly we will iterate over the map and append all the keys in the slice. range loop construct. Among its many features, slices stand out as a versatile and dynamic data structure for managing sequences of elements. So you may simply convert a round number to big. A slice is a segment of dynamic arrays that can grow and shrink as you see fit. Value wrapping the field. It’s compiled, open source, and strongly typed. In this tutorial, we will learn about Arrays and Slices in Go. 1) if a value is a map - recursively call the method. Printf("index: %d, value: %d ", i, numbers[i]) } } Output Prepare every slice as a map: m1 := make(map[int]string) for i:=0; i < len(s1); i ++ { m1[s1[i]. The Go for range form can be used to iterate over strings, arrays, slices, maps, and channels. Println() function where ln means new line. Step 2 − Create a function main and in that function create a string of which each character is iterated. The wording is misleading (even though the intent is clear and correct): a variable of type []T is a slice, and a := make([]T); b = a produces two distinct slices; the "problem" is that the both slices there share the same underlying array. (T) is called a Type Assertion. Basic Iteration Over Maps. An array can iterate and loop over each element in a map. arrayName is the variable name for this string array. Finally iterate once: for i:=0; i < len(s1); i ++ { fmt. . There are multiple ways to count the occurrence of a specific character in a slice, such as using a loop, a map, or the strings. TLDR: ReadDir is lazy and Readdir is eagerIn both Go Playground links, I've created a struct, then I'm iterating through the NumField() values derived via reflect. Each time round the loop, dish is set to the next key, and price is set to the corresponding value. a six bytes large integer), you have to first extend the byte slices with leading zeros until it. 1. Using recursion: You can use a recursive function to iterate over an array or slice. 0. Previous article WCD Kolar Anganwadi Jobs Notification 2022 – 101 Posts, Salary, Application Form. How do I loop over a struct slice in Go? type Fruit struct { Number string Type string } type Person struct { Pid string Fruits []Fruit } func main () { var p Person str. What range then does, is take each of the items in the collection and copy them into the memory location that it created when you called range. Your slices sample isn't random but a known index. 10. Share . Different methods to get golang length of map. Println () function where ln means new line. We can create a loop with the range operator and iterate through the slice of strings. To create a Go slice backed by a C array (without copying the original data), one needs to acquire this length at runtime and use a type conversion to a pointer to a very big array and then slice it to the. Access a map value using a variable key in a Go template. A slice is a dynamic sequence which stores element of similar type. Viewed 984 times. For performing operations on arrays, the need arises to iterate through it. In Golang Range keyword is used in different kinds of data structures in order to iterates over elements. The number of initial values must be less than or. It has significantly more memory allocations: one allocation for a slice and one allocation for. Slice is one of the most common data type used in Golang. ValueOf (p) typ. The code s = fmt. Iterate over the map by the sorted slice. If you want to iterate over a slice in reverse, the easiest way to do so is through a standard for loop counting down: main. Iterating Over a Slice. 1 Answer. Golang's for loop is also useful when working with arrays, slices, and maps. The "range" keyword in Go is used to iterate over the elements of a collection, such as an array, slice, map, or channel. To iterate over other types of data, an iterator function with callbacks is a clean and fairly efficient abstraction. e. Call Join () function and pass the strings as a slice for first argument, and the delimiter string as second argument. . Println ("Hello, playground") var foo []string // nil slice. There are a few ways you can do it, but the common theme between them is that you want to somehow transform your data into a type that Go is capable of ranging over. range loop. Example. The value of the pipeline in Action must be an array (or slice). While this isn't the most efficient way (especially for large arrays or slices), it is an interesting. go. An array is a collection of elements of a single data type. sets all elements up to the length of s to the zero value of T. Not necessarily better, but the cleaner way to do this is by defining both the Slice LENGTH and CAPACITY like txs := make ( []Tx, 0, len (txMap)) // Defines the Slice capacity to match the Map elements count txs := make ( []Tx, 0, len (txMap)) for _, tx := range txMap { txs = append (txs, tx) }Check if Slice contains Specific Element. Which means if you modify the elements of the new slice, the original will also observe those changes. org, Go allows you to easily convert a string to a slice of runes and then iterate over that, just like you wanted to originally: runes := []rune ("Hello, 世界") for i := 0; i < len (runes) ; i++ { fmt. This would let you easily update just your top-level configuration file each January 1st, instead of hunting through your templates. You are attempting to iterate over a pointer to a slice which is a single value, not a collection therefore is not possible. How familiar are you with the representation of different data structures and the concept of algorithmic complexity? Iterating over an array or slice is simple. Modified 4 years, 6 months ago. A for loop is used to iterate over data structures in programming languages. If it's possible that more than one element will be deleted, then use. ValueOf (p) typ. 6. One correct option is to iterate the string elements, comparing each char to the previous one. We then start the while loop that checks if the count is less than the number of items in the slice. Golang is an awesome, simple, modern, and fast programming language. If the value of the pipeline has length zero, nothing is output; otherwise, dot is set to the successive elements of the array, slice, or map. Using three statements for loop We can use the three statements for loop i. When ranging over a slice, two values are returned for each iteration. There are a few ways you can do it, but the common theme between them is that you want to somehow transform your data into a type that Go is capable of ranging over. The syntax to declare and initialize an array arrayName of size arraySize in which elements of type arrayDataType are stored is. The short answer is no. Golang - How to iterate through two slices at the same time. Example, given an array: arr := []int {2, 5, 7, 1} I want a slice with the following output: [1 7 5 2] I know one approach would be to use a for loop but I was wondering if there was a more efficient solution. Looping through slices. Println ("sum:", sum): range. TL;DR package main import "fmt" func main { // slice of names names := [] string {"John Doe", "Lily Roy", "Roy Daniels"} // loop through every item in the `names` // slice using the `for` keyword // and the `range` operator. A slice is a segment of dynamic arrays that can grow and shrink as you see fit. 1. Here is the code I used: type Object struct { name string description string } func iterate (aMap map [string]interface {}, result * []Object. To create String Array, which is to declare and initialize in a single line, we can use the syntax of array to declare and initialize in one line as shown in the following. Six}}{{. This comes down to the representation in memory. This comes down to the representation in memory. Meanwhile, function ReturnSliceWithPointers looks worse: less performance and less memory efficiency. Like arrays, slices are index-able and have a length. In go , the iteration order over a map is not guranteed to be reproducible. Slices are made up of multiple elements, all of the same type. They syntax is shown below: for i := 0; i < len(arr); i++ { // perform an operation } As an example, let's loop through an array of integers:Modified 10 years, 2 months ago. Iterating through a slice and resetting the index - golang. Inserting into slice. To cite the append() manual: «The variadic function append appends zero or more values x to s of type S,. This will give a sorted slice/list of keys of the map. g. 21 (released August 2023) you have the slices. The for loop is the only loop available in Go. A slice can grow and shrink within the bounds of the underlying array. range within range golang template. We’ll import the necessary packages for the API calls to Elasticsearch and declare at the top of the script: "context""fmt""log"// log errors. Right now I have a messy switch-case that's not really scalable, and as this isn't in a hot spot of my application (a web form) it seems leveraging reflect is a good choice here. To iterate over characters of a string in Go language, we need to convert the string to an array of individual characters which is an array of runes, and use for loop to iterate over the characters. if no matches in the slice, exit to the OS. To iterate over other types of data, an iterator function with callbacks is a clean and fairly efficient abstraction. I am trying to iterate over a map of interfaces in golang, it has the below structure, I am able to use for loop to iterate to a single level but couldn't go deep to get values of the interface. Slice - 30 examples found. @adarian while the length of a slice might be unknown at compile time, at run time it can be discovered using the built-in function len. For example, for i, v := range array { //do something with i,v }. len() function returns an integer, the length of slice. Split a string on , using func (s string) []string { return strings. Note how even if you grow more string slices, it's just the one place you need to add the list. If n is an integer type, then for x := range n {. Then iterate over that slice to retrieve the values from the map, so that we get them in order (since slice composed of keys is sorted, so will be in reproducible order). Age: 19, } The first copies of the values are created when the values are placed into the slice: dogs := []Dog {jackie, sammy} The second copies of the values are created when we iterate over the slice: dog := range dogs. Reverse(. 2. When it iterates over the elements of an array and slices then it returns the index of the element in an integer. Seq[Item]. Elements of an array are accessed through indexes. From Effective Go: If you're looping over an array, slice, string, or map, or reading from a channel, a range clause can manage the loop. ReadAll(resp. Step 2 − Create a function main and in that function create a make a dictionary dict_values using map function that contains key-value pairs. If the argument type is a type parameter, all types in its type set must be maps or slices, and clear performs the operation corresponding to the actual type argument. Unconventional Methods 1. To add elements to a slice, use the append builtin. ) func main () {. Golang Remainder Operator applies to integers only. That. Below are explanations with examples covering different scenarios to convert a Golang interface to a string using fmt. Run the following command. A slice of structs is not equal to a slice of an interface the struct implements. If the map or slice is nil, clear is a no-op. Reverse (you need to import slices) that reverses the elements of the slice in place. But to be clear, this is most certainly a hack. Iterate over one of them, and compare each rune with the corresponding rune in the other. Reflection goes from interface value to reflection object. CollectionID 2:Iterate on a golang array/slice without using for statement. The idiomatic way to iterate over a map in Go is by using the for. Println (i, a [i]) //0 a 1 b 2 c i += 1 num (a, i) //tail recursion } } func main () { a. g. 2. Since the release of Go 1. So we don't need to check the length of a slice must be bigger than zero as other languages like PHP or Python. Go slices and loops: Multilple loop through slice items while reducing the items with 1 each on each loop. range on a map returns two values (received as the variables dish and price in our example), which are the key and value respectively. for i := 0; i < len(s); i++ {, without causing index-out-of-bounds errors. Sometimes we need to iterate over a slice or array of items. The type []T is a slice with elements of type T. Looks like it works with single item marked to remove, but it will fail soon with panic: runtime error: slice bounds out of range, if there are more than one item to remove. We use a range to iterate over a slice. for i := 0; i < len(x); i++ { //x[i] } Examples Iterate over Elements of Slice. 1. fmt. In this example, we create a map numberMap. To create an empty Map in Go language, we can either use make () function with map type specified or use map initializer with no key:value pairs given. TLDR: ReadDir is lazy and Readdir is eager 5. In Go, in order to iterate over an array/slice, you would write something like this: for _, v := range arr { fmt. arrayName := [arraySize] arrayDataType {value1, value2} The initial values are given as comma separated values enclosed in curly braces as shown in the code above. 1 Answer. This can be seen in the function below: func Reverse(input []int) [] int { var output [] int for i := len (input) - 1; i >= 0; i-- { output = append (output, input [i]) } return output }I want to pass a slice that contains structs and display all of them in the view. Using the Printf() function, we print the index and the value. From the docs for text/template (serves as interface docs for html/template): { {range pipeline}} T1 { {end}} The value of the pipeline must be an array, slice, map, or channel. It's not necessary to pass a pointer in this situation, nor is there a performance benefit to passing a pointer. The range keyword allows you to loop over each key-value pair in the map. Replace function replaces only specified N occurrences of the substring, while ReplaceAll function replaces all the occurrences of given substring with the new value. Is there a better way to iterate over fields of a struct? 2. This code creates a new slice of integers, appends two elements to it, and prints the resulting slice. UserCreatedEntity is an interface, and Idea satisfies the interface, so you can return an Idea from a function whose signature has a return type of UserCreatedEntity. iterating over over a 2D slice in go. Interface() which makes it quite verbose to use (whereas sort. package main import "fmt" func num (a []string, i int) { if i >= len (a) { return } else { fmt. To clarify previous comment: sort. Slices. The Split function takes a string and a delimiter as parameters and returns a slice of strings where each substring was formally separated by the given. See the table to compare the properties of the nil and empty. An array holds a fixed number of elements, and it cannot grow or shrink. From what I've read this is a way you can iterate trough struct fields/values without hard coding the field names (ie, I want to avoid hardcoding references to FirstSlice and SecondSlice in my loop). 0, the runtime has randomized map iteration order. Let’s. Using the For Loop with Arrays, Slices, and Maps. Nearly to “How do reverse a slice in Golang” How to Write the log to the specified file in Golang; Network port forwarding with TLS in golang; New or Make for Go data structure creation; Parsing jsonp string in Golang; Remove digits from string in Go; Send an interrupt signal in Golang; Sending POST request in Golang with headerDifferent methods to iterate over an array in golang. I faced with a problem how to iterate through the map[string]interface{} recursively with additional conditions. Iterate through struct in golang without reflect. > "golang-nuts" group. The type [n]T is an array of n values of type T. A community built and contributed collection of practical recipes for real world Golang development. For a of pointer to array type: a [x] is shorthand for (*a) [x] For a of slice type S: if x is out of range at run time, a run-time panic occurs. Getting and setting length of arbitrary slice. Golang – Create empty Map; Golang – Map. To replace a substring in string with a new value in Go programming, we can use either Replace function or ReplaceAll function of the strings package. . someslice[min:max]), the new slice will share the backing array with the original one. Int1, etc. It can be used here in the following ways: Example 1: When you need to store a lot of elements or iterate over elements and you want to be able to readily modify those elements, you’ll likely want to work with the slice data type. How to Iterate Over a Slice in Golang? You can loop through the list items by using a for loop. Site. As I understand range iterates over a slice, and index is created from range, and it's zero-based. // // Range does not necessarily correspond to any consistent snapshot of the Map. So, if we are interested in a string as runes, we should convert the string to a slice of runes: ar, br := []rune( a), []rune( b) This allows us to safely compare the runes: The lengths of the rune slices. Let’s say we have a map of the first and last names of language designers. This is what I tried: In Golang, you can loop through an array using a for loop by initialising a variable i at 0 and incrementing the variable until it reaches the length of the array. Step 4 − The print statement is executed using fmt. 3 goals: 'dependency-check:check' concurrent: false. Notice that it has a capacity equal to the size of the map. In general though, maps would normally be O (1) complexity, meaning that it takes a constant time to lookup any element in any part of the map by it’s key, whereas the complexity for a slice would be 0 (n), meaning that it can take as long as the number of elements in the slice to find a single element since you have to loop over each element. The code sample above, generates numbers from 0 to 9. The slice will be pointer to map key. This project started as an experiment with the new generics implementation. If so, my guess as to why the output is exactly 0A, 1M, 2C, - because, originally, the slice was passed to the loop by pointer, and when the capacity of the slice is doubled in the first iteration of the loop, the print(i, s). Iterating through elements is often necessary when dealing with arrays, and the case is no different for a Golang array of structs. and lots of other stufff that's different from the other structs } type B struct { F string //. 1. I just need a way to take values of one struct, iterate over the original struct and update its value. To iterate on Go’s map container, we can directly use a for loop to pass through all the available keys in the map. 75 bacon 3. Sort(sort. nums:= [] int {2, 3, 4} sum:= 0 for _, num:= range nums {sum += num} fmt. How to iterate over a range of numbers in. For each class type there are several classes, so I want to group all the Yoga classes, and all the Pilates classes and so on. Step 4 − Create an empty slice using make function to append the values of difference between two slices. Go NOT Operator ! computes the logical NOT operation. 3. 1 - John 2 - Mary 3 - Steven 4 - MikeA slice is a flexible and extensible data structure to implement and manage collections of data. A slice is growable, contrary to an array which has a fixed length at compile time. If the value of the length of the slice is zero, nothing is output; otherwise, dot (aka cursor) is set to the successive elements of the array, slice and Template is executed. I needed to iterate over some collection type for which the exact storage implementation is not set in stone yet. for _, attr := range n. Third by using a for (while) loop. After that, we can simply iterate over this slice and access the value from the key in the map. Modified 9 years, 6 months ago. g. In Go, there are two functions that can be used to. Instead we could put pointers of type *MyStruct inside the slice. Scan (&firstName, &lastName, &GPA) applicants = append (applicants, Applicant {firstName, lastName, GPA}) Now my task is to output only names of first 3 applicants with highest GPA. You could either do a simple loop such as for d := Monday; d <= Sunday; d++ {} where you. Here's an example of how to iterate through the fields of a struct: package main import ( "fmt" "reflect" ) type Movie struct { Name string Year int } func main () { p := Movie {"The Dark Knight", 2008} val := reflect. As mentioned by @LeoCorrea you could use a recursive function to iterate over a slice. Yaml. A, etc 100 times. To clarify previous comment: sort. myMap [1] = "Golang is Fun!" 2 Answers. When you iterate over a slice of values, the iteration variables will be copies of those values. Golang: loop through fields of a struct modify them and and return the struct? 0 Using reflection to iterate over struct's struct members and calling a method on it Go slice tutorial shows how to work with slices in Golang. Reverse() does not sort the slice in reverse order. Firstly we will iterate over the map and append all the keys in the slice. The first is the index, and the second is a copy of. Also for small data sets, map order could be predictable. To get started, there are two types we need to know about in package reflect : Type and Value . Use maps in Go templates. First by using for range loop. Since you know the final size of keys from the romanNumeralDict outset, it is more efficient to allocate an array of the required size up front. body, _ := ioutil. In the real code there are many more case statements, but I removed them from the post to make the problem more concise. Here, we are going to learn how to iterate a slice using a range in 'for' loop without index in Golang (Go Language)? Submitted by Nidhi, on March 15, 2021 [Last updated : March 04, 2023] . Slice to struct in go. The syntax to check if string substr is present in the string str is. where filename is the name of the file with go code. Output. Also for small data sets, map order could be predictable. To iterate over slices, simply use Value. In Java, we can iterate as below. Running the example code with two different maps, you get the output: And. However, there is a recent proposal by RSC that extends the range to iterate over integers. The easiest way to do this is to simply interpret the bytes as a big-endian integer. Golang AND. 0 Answers Avg Quality 2/10. [1,2,3,4] //First Iteration [5,6,7,8] //Second Iteration [9,10,11,12] //Third Iteration [13,14,15,] // Fourth Iteration.