Booleans in Go

0
User Management System
Learn Kotlin, Retrofit, MVVM and MySQL using this all-in-one app. It is designed to be beginner friendly.

A Boolean Value is a value with only two possible states: true or false. In Go if no value is provided to boolean variable then false is set as the default.

Go Boolean Example

Here's a boolean example in Go:

// create main package
//The package “main” tells the Go compiler that the package should compile as an executable
// program instead of a shared library.
package main

//fmt -> A Package that implements formatted I/O with functions analogous to C's printf and scanf.
import "fmt"

//create main function ->  the entry point of our executable program.
func main() {
    // create a boolean variable and assign it a value
    var me bool = true
    //Printf -> formats strings according to a format specifier and writes to standard output.
    //%v -> the value in a default format when printing structs
    // \n -> new line operator
    fmt.Printf("me is: '%v'\n", me)

    //you can reassign thevalue of the me variabe
    me = false
    fmt.Printf("me is: '%v'\n", me)

    var b2 bool
    fmt.Printf("zero value of bool is: '%v'\n", b2)
    // :show end
}

If you run it you get the following:

me is: 'true'
me is: 'false'
zero value of bool is: 'false'

Learn Android Retrofit using our course

Android MySQL Retrofit2 Multipart CRUD,Search,Pagination rating

When I was a 2nd year Software Engineering student, I buillt a now defunct online tool called Camposha(from Campus Share) using my then favorite language C#(ASP.NET) to compete OLX in my country(Kenya). The idea was to target campus students in Kenya. I got a few hundred signups but competing OLX proved too daunting. I decided to focus on my studies, learning other languages like Java,Python,Kotlin etc while meanwhile publishing tutorials at my YouTube Channel ProgrammingWizards TV which led to this site(camposha.info). Say hello or post me a suggestion: oclemmi@gmail.com . Follow me below; Github , and on my channel: ProgrammingWizards TV

We will be happy to hear your thoughts

Leave a reply

− two = eight

Reset Password
Compare items
  • Total (0)
Compare
0
Shopping cart