Google’s Go programming language (Golang) is gaining momentum and IMHO it has the potential to become one of the most popular languages in near future. It’s clean, simple and at the same time addresses a few of the challenges of modern computing. There’s no statistics to support but Go is getting popular with programmers of almost all the languages. From whatever unstructured data is available on the web it seems Go is getting highly popular among Ruby & Python programmers.
This is the 3rd post on Golang at CodingThis. You can read the last one here Google Go Programming – For Loop Adventure.
The purpose of this article is to generate curiosity among Go newcomers. That’s the reason I’m sharing a construct that is available in every language – if else.
Let us see the code below:
package main
import (
"fmt"
"time"
"strconv" )
func main() {
str := "Enter your name and amount to be withdrawn?"
var name string
var withdraw int
today := time.Now().Format(time.RFC850)
fmt.Println(str)
fmt.Scanf("%s %d", &name, &withdraw)
fmt.Println("Hello", name+": your bank balance on " +today+ " is
only $100")
if withdraw >= 100 {
fmt.Println("You can't withdraw $" +strconv.Itoa(withdraw)+" - Insufficient balance")
} else { fmt.Println("Transaction in process...")
}
}
Once you have installed Go in your system, open a notepad and copy paste the above code. Execute the code. You will get the output as follows:
1. If you enter the withdrawal amount as 100 or more than 100 then you get the following output of insufficient balance:
2. If you enter the withdrawal amount as less than 100 then you get the following output of transaction in process:
Learning from the above code snippet:
- Variable declaration
- Use of Scanf function
- Use of if else
Please share and spread the word if you think it can help a Go new comer.
Basant Singh
Latest posts by Basant Singh (see all)
- Go Maps Introduction for Beginners - May 20, 2015
- Go Programming – Arrays and Slices - May 11, 2015
- Golang Switch Case with Sample Code - May 1, 2015