<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Variables and loops in golang Day 3]]></title><description><![CDATA[Variables and loops in golang Day 3]]></description><link>https://malka-day2-of-learning-development.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 25 Jun 2026 04:20:14 GMT</lastBuildDate><atom:link href="https://malka-day2-of-learning-development.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Beginner's Guide to Variables and Loops in Go]]></title><description><![CDATA[---
# Hey, I'm Malka! 👋
Welcome to **Day 2** of my **#100DaysOfDevelopment** journey. Today, I’m diving into **Variables and Loops in Go (Golang)**.
I'm currently learning from [**Go by Example**](https://gobyexample.com/) — an excellent hands-on re...]]></description><link>https://malka-day2-of-learning-development.hashnode.dev/a-beginners-guide-to-variables-and-loops-in-go</link><guid isPermaLink="true">https://malka-day2-of-learning-development.hashnode.dev/a-beginners-guide-to-variables-and-loops-in-go</guid><category><![CDATA[Basicsofgolang]]></category><category><![CDATA[Loops]]></category><category><![CDATA[variables]]></category><category><![CDATA[Golang developer]]></category><category><![CDATA[100DaysOfCode]]></category><category><![CDATA[golang]]></category><category><![CDATA[constants in go]]></category><dc:creator><![CDATA[Malka Ali]]></dc:creator><pubDate>Wed, 25 Jun 2025 15:20:34 GMT</pubDate><content:encoded><![CDATA[<p>---</p>
<p># Hey, I'm Malka! 👋</p>
<p>Welcome to **Day 2** of my **#100DaysOfDevelopment** journey. Today, I’m diving into **Variables and Loops in Go (Golang)**.</p>
<p>I'm currently learning from [**Go by Example**](https://gobyexample.com/) — an excellent hands-on resource for beginners!</p>
<p>---</p>
<p>## 🧠 Understanding Variables in Go</p>
<p>We all know that a **variable** is like a container that stores data. But Go brings its own twist. Here's what I’ve learned so far:</p>
<p>---</p>
<p>### ✅ 1. **Basic Declaration**</p>
<p>Go uses the `var` keyword to declare variables:</p>
<p>```go</p>
<p>var a string</p>
<p>You can also declare multiple variables of the same type on a single line:</p>
<p>var a, b int</p>
<p>---</p>
<p>🧩 2. Type Inference</p>
<p>Go can infer the variable type from the value you assign:</p>
<p>var a = "hello"</p>
<p>Here, you don’t need to mention string — Go automatically figures it out.</p>
<p>\&gt; ⚠️ You must assign a value in this case, otherwise the compiler will throw an error.</p>
<p>---</p>
<p>⚡ 3. Shorthand Declaration</p>
<p>Go provides a short and clean way to declare and initialize variables using :=:</p>
<p>f := "apple"</p>
<p>fmt.Println(f)</p>
<p>No need for var</p>
<p>No need to specify the type</p>
<p>Must initialize at the same time</p>
<p>\&gt; 🔒 This shorthand doesn't work for constants or without initialization.</p>
<p>---</p>
<p>🛑 4. Declaring Variables of Different Types</p>
<p>You can’t do this:</p>
<p>// ❌ Invalid</p>
<p>var a int, b string</p>
<p>But Go allows multiple declarations with inferred types:</p>
<p>// ✅ Valid</p>
<p>var a, b = 10, "Malka"</p>
<p>Or even shorter:</p>
<p>a, b := 10, "Malka"</p>
<p>---</p>
<p>🔐 Constants in Go</p>
<p>Constants are declared using the const keyword:</p>
<p>const a = 7</p>
<p>If a value is provided, Go will infer the type.</p>
<p>Constants cannot be changed after they’re declared.</p>
<p>You cannot use := for constants.</p>
<p>---</p>
<p>🔁 Loops in Go</p>
<p>Go has only one loop keyword — for. But it’s super flexible!</p>
<p>---</p>
<p>🔹 1. Standard For Loop</p>
<p>Similar to C/C++, but Go-style:</p>
<p>for i := 0; i &lt; 5; i++ {</p>
<p>fmt.Println(i)</p>
<p>}</p>
<p>---</p>
<p>🔸 2. While-Like Loop</p>
<p>i := 0</p>
<p>for i &lt;= 10 {</p>
<p>fmt.Println(i)</p>
<p>i++</p>
<p>}</p>
<p>---</p>
<p>🔁 3. Infinite Loop</p>
<p>for {</p>
<p>fmt.Println("I am an infinite loop")</p>
<p>}</p>
<p>To stop it, press Ctrl + C or use a break statement:</p>
<p>for {</p>
<p>fmt.Println("Only once")</p>
<p>break</p>
<p>}</p>
<p>---</p>
<p>🔄 4. Looping a Fixed Number of Times (Using range)</p>
<p>for i := range 3 {</p>
<p>fmt.Println(i)</p>
<p>}</p>
<p>This acts like a loop from 0 to 2 — useful for repeating tasks a fixed number of times.</p>
<p>---</p>
<p>🎯 What I Learned Today</p>
<p>✅ Variable declaration and initialization</p>
<p>✅ Shorthand syntax using :=</p>
<p>✅ Constants in Go</p>
<p>✅ Flexible use of the for loop</p>
<p>✅ How Go syntax differs from C/C++</p>
<p>---</p>
<p>🔜 What’s Next?</p>
<p>On Day 3, I’ll explore if/else statements in Go — diving into decision-making logic.</p>
<p>I’m also brainstorming some unique beginner-friendly project ideas. I want to go beyond basic calculators or to-do apps and build something useful, creative, and different.</p>
<p>💡 Got a cool idea? Drop it in the comments or send me a DM — I’d love to connect and collaborate!</p>
<p>---</p>
<p>💬 Let’s Connect!</p>
<p>I'm documenting my journey in simple, beginner-friendly language to help others learn alongside me.</p>
<p>Follow along, and let’s grow together on this path of development 🚀</p>
<p>Thanks for reading!</p>
]]></content:encoded></item></channel></rss>