{"id":120,"date":"2025-04-02T02:41:16","date_gmt":"2025-04-02T02:41:16","guid":{"rendered":"https:\/\/techkubo.com\/go\/?p=120"},"modified":"2025-05-26T18:00:02","modified_gmt":"2025-05-26T18:00:02","slug":"go-for-loops","status":"publish","type":"post","link":"https:\/\/techkubo.com\/go\/go-for-loops\/","title":{"rendered":"Go For Loops"},"content":{"rendered":"\n<p>In <strong>Go<\/strong>, the <code>for<\/code> loop is the only looping construct provided by the language. It&#8217;s versatile and efficient for executing a block of code multiple times, often with a unique value in each iteration. Each cycle through the loop is referred to as an iteration.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax of a for Loop<\/h2>\n\n\n\n<p>The <code>for<\/code> loop in Go can include up to three statements:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">for initialization; condition; increment {\n   \/\/ code to execute during each iteration\n}\n<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Initialization<\/strong>: This sets up the loop control variable.<\/li>\n\n\n\n<li><strong>Condition<\/strong>: This evaluates before each iteration. If <code>TRUE<\/code>, the loop continues; if <code>FALSE<\/code>, the loop ends.<\/li>\n\n\n\n<li><strong>Increment<\/strong>: This modifies the loop control variable after each iteration.<\/li>\n<\/ul>\n\n\n\n<p>Note: These statements don\u2019t need to be included within the loop header but must exist elsewhere in the code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example 1: Counting from 0 to 4<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">package main\nimport (&quot;fmt&quot;)\n\nfunc main() {\n  for bikes := 0; bikes &lt; 5; bikes++ {\n    fmt.Println(bikes)\n  }\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">0\n1\n2\n3\n4\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Explanation<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Initialization<\/strong>: <code>bikes := 0<\/code> sets the starting value to 0.<\/li>\n\n\n\n<li><strong>Condition<\/strong>: <code>bikes &lt; 5<\/code> ensures the loop runs as long as <code>bikes<\/code> is less than 5.<\/li>\n\n\n\n<li><strong>Increment<\/strong>: <code>bikes++<\/code> increases the value of <code>bikes<\/code> by 1 in each iteration.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Example 2: Counting in Tens<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">package main\nimport (&quot;fmt&quot;)\n\nfunc main() {\n  for motorcycles := 0; motorcycles &lt;= 100; motorcycles += 10 {\n    fmt.Println(motorcycles)\n  }\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">0\n10\n20\n30\n40\n50\n60\n70\n80\n90\n100\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Explanation<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Initialization<\/strong>: <code>motorcycles := 0<\/code> starts at 0.<\/li>\n\n\n\n<li><strong>Condition<\/strong>: <code>motorcycles &lt;= 100<\/code> keeps the loop running while <code>motorcycles<\/code> is less than or equal to 100.<\/li>\n\n\n\n<li><strong>Increment<\/strong>: <code>motorcycles += 10<\/code> increases the value by 10 with each cycle.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Continue Statement<\/h2>\n\n\n\n<p>The <code>continue<\/code> statement skips the remainder of the current loop iteration and proceeds to the next iteration.<\/p>\n\n\n\n<p>Example: Skipping a specific value (e.g., 3):<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">package main\nimport (&quot;fmt&quot;)\n\nfunc main() {\n  for models := 0; models &lt; 5; models++ {\n    if models == 3 {\n      continue\n    }\n    fmt.Println(models)\n  }\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">0\n1\n2\n4\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Break Statement<\/h2>\n\n\n\n<p>The <code>break<\/code> statement halts the loop\u2019s execution entirely.<\/p>\n\n\n\n<p>Example: Terminating the loop when a condition is met:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">package main\nimport (&quot;fmt&quot;)\n\nfunc main() {\n  for brands := 0; brands &lt; 5; brands++ {\n    if brands == 3 {\n      break\n    }\n    fmt.Println(brands)\n  }\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">0\n1\n2\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nested Loops<\/h2>\n\n\n\n<p>Loops can be nested, meaning one loop is placed inside another. The inner loop runs completely during each iteration of the outer loop.<\/p>\n\n\n\n<p>Example: Combining two lists, such as adjectives and motorcycle brands:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">package main\nimport (&quot;fmt&quot;)\n\nfunc main() {\n  adjectives := [2]string{&quot;sleek&quot;, &quot;powerful&quot;}\n  brands := [3]string{&quot;Ducati&quot;, &quot;Yamaha&quot;, &quot;Honda&quot;}\n  for i := 0; i &lt; len(adjectives); i++ {\n    for j := 0; j &lt; len(brands); j++ {\n      fmt.Println(adjectives[i], brands[j])\n    }\n  }\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">sleek Ducati\nsleek Yamaha\nsleek Honda\npowerful Ducati\npowerful Yamaha\npowerful Honda\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using the range Keyword<\/h2>\n\n\n\n<p>The <code>range<\/code> keyword provides a convenient way to iterate over elements in arrays, slices, or maps. It returns both the index and the value.<\/p>\n\n\n\n<p><strong>Syntax<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">for index, value := range collection {\n   \/\/ code to execute during each iteration\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Example: Iterating through motorcycle brands:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">package main\nimport (&quot;fmt&quot;)\n\nfunc main() {\n  brands := [3]string{&quot;Suzuki&quot;, &quot;Honda&quot;, &quot;Ducati&quot;}\n  for idx, val := range brands {\n    fmt.Printf(&quot;%v\\t%v\\n&quot;, idx, val)\n  }\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;go&quot;,&quot;mime&quot;:&quot;text\/x-go&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;Go&quot;,&quot;language&quot;:&quot;Go&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;go&quot;}\">0      Suzuki\n1      Honda\n2      Ducati<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Additional Tips for <code>range<\/code><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>To ignore the index<\/strong>: <code>for _, val := range brands { fmt.Println(val) }<\/code> <strong>Output<\/strong>: <code>Suzuki Honda Ducati<\/code><\/li>\n\n\n\n<li><strong>To ignore the value<\/strong>: <code>for idx, _ := range brands { fmt.Println(idx) }<\/code> <strong>Output<\/strong>: <code>0 1 2<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In Go, the for loop is the only looping construct provided by the language. It&#8217;s versatile and efficient for executing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Go For Loops - Go Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techkubo.com\/go\/go-for-loops\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go For Loops - Go Tutorial\" \/>\n<meta property=\"og:description\" content=\"In Go, the for loop is the only looping construct provided by the language. It&#8217;s versatile and efficient for executing [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techkubo.com\/go\/go-for-loops\/\" \/>\n<meta property=\"og:site_name\" content=\"Go Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-02T02:41:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-26T18:00:02+00:00\" \/>\n<meta name=\"author\" content=\"Manong\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/techkubo.com\/go\/go-for-loops\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/go\/go-for-loops\/\"},\"author\":{\"name\":\"Manong\",\"@id\":\"https:\/\/techkubo.com\/go\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\"},\"headline\":\"Go For Loops\",\"datePublished\":\"2025-04-02T02:41:16+00:00\",\"dateModified\":\"2025-05-26T18:00:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/techkubo.com\/go\/go-for-loops\/\"},\"wordCount\":305,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/go\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/techkubo.com\/go\/go-for-loops\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/techkubo.com\/go\/go-for-loops\/\",\"url\":\"https:\/\/techkubo.com\/go\/go-for-loops\/\",\"name\":\"Go For Loops - Go Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/go\/#website\"},\"datePublished\":\"2025-04-02T02:41:16+00:00\",\"dateModified\":\"2025-05-26T18:00:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/techkubo.com\/go\/go-for-loops\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/techkubo.com\/go\/go-for-loops\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/techkubo.com\/go\/go-for-loops\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/techkubo.com\/go\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go For Loops\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/techkubo.com\/go\/#website\",\"url\":\"https:\/\/techkubo.com\/go\/\",\"name\":\"Go Tutorial\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/go\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/techkubo.com\/go\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/techkubo.com\/go\/#organization\",\"name\":\"Go Tutorial\",\"url\":\"https:\/\/techkubo.com\/go\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/go\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/techkubo.com\/go\/wp-content\/uploads\/sites\/13\/2025\/04\/cropped-cropped-Techkubo-logo-1-300x220-1.png\",\"contentUrl\":\"https:\/\/techkubo.com\/go\/wp-content\/uploads\/sites\/13\/2025\/04\/cropped-cropped-Techkubo-logo-1-300x220-1.png\",\"width\":300,\"height\":220,\"caption\":\"Go Tutorial\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/go\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/techkubo.com\/go\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\",\"name\":\"Manong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/go\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"caption\":\"Manong\"},\"sameAs\":[\"https:\/\/techkubo.com\"],\"url\":\"https:\/\/techkubo.com\/go\/author\/manong\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go For Loops - Go Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techkubo.com\/go\/go-for-loops\/","og_locale":"en_US","og_type":"article","og_title":"Go For Loops - Go Tutorial","og_description":"In Go, the for loop is the only looping construct provided by the language. It&#8217;s versatile and efficient for executing [&hellip;]","og_url":"https:\/\/techkubo.com\/go\/go-for-loops\/","og_site_name":"Go Tutorial","article_published_time":"2025-04-02T02:41:16+00:00","article_modified_time":"2025-05-26T18:00:02+00:00","author":"Manong","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manong","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techkubo.com\/go\/go-for-loops\/#article","isPartOf":{"@id":"https:\/\/techkubo.com\/go\/go-for-loops\/"},"author":{"name":"Manong","@id":"https:\/\/techkubo.com\/go\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965"},"headline":"Go For Loops","datePublished":"2025-04-02T02:41:16+00:00","dateModified":"2025-05-26T18:00:02+00:00","mainEntityOfPage":{"@id":"https:\/\/techkubo.com\/go\/go-for-loops\/"},"wordCount":305,"commentCount":0,"publisher":{"@id":"https:\/\/techkubo.com\/go\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techkubo.com\/go\/go-for-loops\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techkubo.com\/go\/go-for-loops\/","url":"https:\/\/techkubo.com\/go\/go-for-loops\/","name":"Go For Loops - Go Tutorial","isPartOf":{"@id":"https:\/\/techkubo.com\/go\/#website"},"datePublished":"2025-04-02T02:41:16+00:00","dateModified":"2025-05-26T18:00:02+00:00","breadcrumb":{"@id":"https:\/\/techkubo.com\/go\/go-for-loops\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techkubo.com\/go\/go-for-loops\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/techkubo.com\/go\/go-for-loops\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techkubo.com\/go\/"},{"@type":"ListItem","position":2,"name":"Go For Loops"}]},{"@type":"WebSite","@id":"https:\/\/techkubo.com\/go\/#website","url":"https:\/\/techkubo.com\/go\/","name":"Go Tutorial","description":"","publisher":{"@id":"https:\/\/techkubo.com\/go\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techkubo.com\/go\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techkubo.com\/go\/#organization","name":"Go Tutorial","url":"https:\/\/techkubo.com\/go\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/go\/#\/schema\/logo\/image\/","url":"https:\/\/techkubo.com\/go\/wp-content\/uploads\/sites\/13\/2025\/04\/cropped-cropped-Techkubo-logo-1-300x220-1.png","contentUrl":"https:\/\/techkubo.com\/go\/wp-content\/uploads\/sites\/13\/2025\/04\/cropped-cropped-Techkubo-logo-1-300x220-1.png","width":300,"height":220,"caption":"Go Tutorial"},"image":{"@id":"https:\/\/techkubo.com\/go\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/techkubo.com\/go\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965","name":"Manong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/go\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","caption":"Manong"},"sameAs":["https:\/\/techkubo.com"],"url":"https:\/\/techkubo.com\/go\/author\/manong\/"}]}},"_links":{"self":[{"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/posts\/120"}],"collection":[{"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":3,"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/posts\/120\/revisions\/200"}],"wp:attachment":[{"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techkubo.com\/go\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}