<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>control-flow on Golang</title><link>https://golang.k5kc.com/categories/control-flow/</link><description>Recent content in control-flow on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:13:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/categories/control-flow/index.xml" rel="self" type="application/rss+xml"/><item><title>Go loop - break and continue</title><link>https://golang.k5kc.com/2020/08/16/4.loop-break-and-continue/</link><pubDate>Sun, 16 Aug 2020 00:13:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/4.loop-break-and-continue/</guid><description>Intro break will break out of a loop. It&amp;rsquo;s a way to stop looping.
continue will move on to the next iteration. Let&amp;rsquo;s see it in action.
Examples Example - break package main import &amp;#34;fmt&amp;#34; func main() { pow := make([]int, 10) for i := range pow { pow[i] = 1 &amp;lt;&amp;lt; uint(i) if pow[i] &amp;gt;= 16 { break } } fmt.Println(pow) // [1 2 4 8 16 0 0 0 0 0] } Example - continue package main import &amp;#34;fmt&amp;#34; func main() { pow := make([]int, 10) for i := range pow { if i%2 == 0 { continue } pow[i] = 1 &amp;lt;&amp;lt; uint(i) } fmt.</description></item><item><title>Go - for loop</title><link>https://golang.k5kc.com/2020/08/16/3.for-loop/</link><pubDate>Sun, 16 Aug 2020 00:12:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/3.for-loop/</guid><description>Go has only one looping construct, the for loop. The basic for loop looks as it does in C or Java, except that the ( ) are gone (they are not even optional) and the { } are required. As in C or Java, you can leave the pre and post statements empty.
for init; condition; post { } Examples Example - Go loop for j := 7; j &amp;lt;= 9; j++ { fmt.</description></item><item><title>Go Conditionals - switch</title><link>https://golang.k5kc.com/2020/08/16/2.switch/</link><pubDate>Sun, 16 Aug 2020 00:11:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/2.switch/</guid><description>Intro In addition to the switch keyword, a switch statement has cases. The switch statement switches on some case.
Example - No break required Compared to other programming languages (such as C), Go&amp;rsquo;s switch-case statement doesn&amp;rsquo;t need explicit &amp;ldquo;break&amp;rdquo;, and not have fall-though characteristic. Take the following code as an example:
package main import ( &amp;#34;fmt&amp;#34; ) func checkSwitch(val int) { switch val { case 0: case 1: fmt.Println(&amp;#34;The value is: &amp;#34;, val) } } func main() { checkSwitch(0) checkSwitch(1) } The output is:</description></item><item><title>Go Conditinals - if else statement</title><link>https://golang.k5kc.com/2020/08/16/1.if-else/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/1.if-else/</guid><description>if Statement Simple if syntax The if statement looks as it does in C or Java, except that the ( ) are gone and the { } are required. Like for, the if statement can start with a short statement to execute before the condition. Variables declared by the statement are only in scope until the end of the if. Variables declared inside an if short statement are also available inside any of the else blocks.</description></item></channel></rss>