{"id":7537,"date":"2021-03-22T17:13:47","date_gmt":"2021-03-22T17:13:47","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=7537"},"modified":"2024-04-15T07:41:38","modified_gmt":"2024-04-15T07:41:38","slug":"ranges-in-golang","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/","title":{"rendered":"Ranges and Maps in Golang"},"content":{"rendered":"\r\n<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Ranges and Maps in Golang&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:513,&quot;3&quot;:{&quot;1&quot;:0},&quot;12&quot;:0}\">Ranges and Maps in Golang<\/span><\/h2>\r\n<p>In Go (Golang), ranges and maps are fundamental concepts used for iterating over collections of data and storing key-value pairs, respectively.<\/p>\r\n<p>Ranges in Go provide a convenient and concise way to iterate over elements in arrays, slices, maps, channels, or strings. They enable sequential access to the elements of a collection without needing explicit loop constructs, promoting simpler and more readable code. Ranges are commonly used in Go for tasks like iterating over arrays\/slices to process each element or reading messages from channels.<\/p>\r\n<p>Maps in Go are a key data structure use for storing and retrieving key-value pairs. They provide an efficient way to associate values with keys, allowing constant-time complexity for insertions, deletions, and lookups (on average). Maps in Go are unorder collections, meaning that the iteration order over map elements is not guarante. Maps are widely use in Go for tasks like caching, maintaining counts, or implementing lookup tables.<\/p>\r\n<p>Understanding how to effectively use ranges for iteration and maps for key-value storage is essential for writing efficient and idiomatic Go code. Mastery of these concepts enables developers to leverage Go&#8217;s powerful features for data processing and storage effectively.<\/p>\r\n<h4><strong>Prerequisites<\/strong><\/h4>\r\n\r\n\r\n\r\n<p>Hardware : Local Machine<\/p>\r\n\r\n\r\n\r\n<p>Software : <a href=\"https:\/\/prwatech.in\/blog\/software-installation\/installation-of-visual-studio-code-windows\/\" target=\"_blank\" rel=\"noreferrer noopener\" data-type=\"URL\" data-id=\"https:\/\/prwatech.in\/blog\/software-installation\/installation-of-visual-studio-code-windows\/\">VS Code<\/a>, <a href=\"https:\/\/go.dev\/\">Golang<\/a><\/p>\r\n\r\n\r\n\r\n<p>Simple range program<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7538\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg\" alt=\"\" width=\"478\" height=\"307\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg 409w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30-300x193.jpg 300w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p>Output :<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7539\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1out-4.jpg\" alt=\"\" width=\"488\" height=\"189\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1out-4.jpg 403w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1out-4-300x116.jpg 300w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p>Initializing slices using range.<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7540\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3-25.jpg\" alt=\"\" width=\"648\" height=\"277\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3-25.jpg 775w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3-25-300x129.jpg 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3-25-768x329.jpg 768w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p>Output :<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7541\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3out-4.jpg\" alt=\"\" width=\"447\" height=\"219\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3out-4.jpg 392w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/3out-4-300x147.jpg 300w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p><strong>Map <\/strong><\/p>\r\n\r\n\r\n\r\n<p>Simple map program<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"593\" height=\"659\" class=\"wp-image-7544\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-31.jpg\" alt=\"\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-31.jpg 593w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-31-270x300.jpg 270w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p>Output :<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7545\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/2-31.jpg\" alt=\"\" width=\"545\" height=\"85\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/2-31.jpg 462w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/2-31-300x47.jpg 300w\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" \/><\/figure>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Ranges and Maps in Golang In Go (Golang), ranges and maps are fundamental concepts used for iterating over collections of data and storing key-value pairs, respectively. Ranges in Go provide a convenient and concise way to iterate over elements in arrays, slices, maps, channels, or strings. They enable sequential access to the elements of a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[666,1707],"tags":[668,812,808,815,813,669,814,823,680],"class_list":["post-7537","post","type-post","status-publish","format-standard","hentry","category-go-lang","category-golang-modules","tag-go","tag-go-lang-tutorial","tag-go-language","tag-go-language-ide","tag-go-language-tutorial","tag-golang","tag-golang-ide","tag-maps-in-go-lang","tag-ranges-in-golang"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ranges and Maps in Golang - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Ranges and Maps in Golang - Dive deep with our expert instructors and comprehensive curriculum, Enroll.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ranges and Maps in Golang - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Ranges and Maps in Golang - Dive deep with our expert instructors and comprehensive curriculum, Enroll.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-22T17:13:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-15T07:41:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/\",\"url\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/\",\"name\":\"Ranges and Maps in Golang - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg\",\"datePublished\":\"2021-03-22T17:13:47+00:00\",\"dateModified\":\"2024-04-15T07:41:38+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Ranges and Maps in Golang - Dive deep with our expert instructors and comprehensive curriculum, Enroll.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg\",\"width\":409,\"height\":263},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ranges and Maps in Golang\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ranges and Maps in Golang - Prwatech","description":"Master Ranges and Maps in Golang - Dive deep with our expert instructors and comprehensive curriculum, Enroll.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Ranges and Maps in Golang - Prwatech","og_description":"Master Ranges and Maps in Golang - Dive deep with our expert instructors and comprehensive curriculum, Enroll.","og_url":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2021-03-22T17:13:47+00:00","article_modified_time":"2024-04-15T07:41:38+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg","type":"","width":"","height":""}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/","url":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/","name":"Ranges and Maps in Golang - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg","datePublished":"2021-03-22T17:13:47+00:00","dateModified":"2024-04-15T07:41:38+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Ranges and Maps in Golang - Dive deep with our expert instructors and comprehensive curriculum, Enroll.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/03\/1-30.jpg","width":409,"height":263},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/go-lang\/ranges-in-golang\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Ranges and Maps in Golang"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/7537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=7537"}],"version-history":[{"count":5,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/7537\/revisions"}],"predecessor-version":[{"id":11492,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/7537\/revisions\/11492"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=7537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=7537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=7537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}