Technological avatar

'If' Statement In 'Go'(Learn 'Go' - Part 12)

technological

Published: 25 May 2018 › Updated: 25 May 2018'If' Statement In 'Go'(Learn 'Go' - Part 12)

'If' Statement In 'Go'(Learn 'Go' - Part 12)

The 'If' statement is used to check a certain condition within a function.

We can create a simple program to see 'if' in action.

 
 

package main

import "fmt"

func main(){

x := 1

for i <= 50{

if i % 5 == 0

{fmt.Println(i)}

i++

}

}

 
 

This program will print the multiples of 5 upto 50.

Breakdown Of The Program

  • We declared the variable 'i' and set its initial value to 1.
  • Then, we created a 'for' loop that will run until the value of i hits 50.
  • After that, we use the if statement to check if 'i' is divisible by 5 or not. If it is divisible by 5, it will be printed only if it is divisible by 5.

 
 

 
 
 

Previous Posts In The Series

 
 

Introduction To 'Go' Programming Language(Learn 'Go' - Part 1)

25 Basic Keywords Of The Go Programming Language (Learn 'Go' - Part 2)

How To Set The Go Programming Environment On Your System?(Learn 'Go' - Part 3)

Create Your First Program In Go Language (Learn 'Go' - Part 4)

Strings In 'Go'(Learn 'Go' - Part 5)

Booleans In 'Go'(Learn 'Go' - Part 6)

Numbers In 'Go'(Learn 'Go' - Part 7)

Variables In 'Go'(Learn 'Go' - Part 8)

Constants In 'Go'(Learn 'Go' - Part9)

Multiple Variables In 'Go'(Learn 'Go' - Part10)

For Loop In 'Go'(Learn 'Go' - Part11)


 
 

Upcoming Posts

Switch In 'Go'(Learn 'Go' - Part 13)

Leave 'If' Statement In 'Go'(Learn 'Go' - Part 12) to:

Written by

Hi! This is Technological.

Read more #programming posts


Best Posts From Technological

We have not curated any of technological's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Technological