Senin, 19 September 2016

Go - Switch statement


Hello everyone! Comeback with me, Indomieboy~
Today, I will explain a little bit about Switch on Golang.

-----------------------------------------------------------------------------------------------

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.

In Go programming, switch are of two types:
  • Expression Switch (I will use this)
  • Type Switch

Expression Switch

 The syntax for a Expression Switch statement in Go programming language is as follows:

switch(boolean-expression or integral type){
    case boolean-expression or integral type  :
       statement(s);      
    case boolean-expression or integral type  :
       statement(s); 
    /* you can have any number of case statements */
    default : /* Optional */
       statement(s);
}

Flow Diagram:


(image source: google)

Example:

package main

import "fmt"

func main() {
   /* local variable definition */
   var rank string = "2"
   var marks int = 90

   switch marks {
      case 90: rank = "1"
      case 80: rank = "2"
      case 50,60,70 : rank = "3"
      default: rank = "4"  
   }

   switch {
      case rank == "1" :
         fmt.Printf("WOW! You are a champion!\n" )     
      case rank == "2", rank == "3" :
         fmt.Printf("Well done\n" )      
      case rank == "4" :
         fmt.Printf("Try again\n" )      
      case rank == "5":
         fmt.Printf("Sorry you're loser\n" )
      default:
         fmt.Printf("Invalid rank\n" );
   }
   fmt.Printf("Your rank is  %s\n", rank );      
}
 And this the result:
(image source: my screenshot)
--------------------------------------------------------------------------------------------------------------

Sorry if my grammar full of mistakes

#CMIIW

 -----------------------------------------------------------------------------------------------------------------
Big thank's for Google & many blogger

Sabtu, 10 September 2016

How to Install Notepad++ and GoLang Plugin on Windows 8

 What you needs :

Steps : 

  1. Download and install Golang, from here.
  2. Set up your 'Environment Variables' on Control Panel. In order to do this open Control Panel > Search for 'Environment Variables'.
  3. Click 'New' on system variables.
  4. And create like this.
  5. Click OK and close Control Panel.
  6. Download and install Notepad++.
  7. Download go.xml and then copy it to  <Your install folder>/plugins/APIs
  8. Open Notepad++
  9. On the Notepad++ Toolbar menu select Language -> Define your language
  10. A user defined language window should open. Click the import button and navigate to the UserDefineLang.xml file and open it which you can download from here
  11. Restart Notepad++
  12. On the Notepad++ toolbar menu select Plugins -> Plugins Manager -> Show Plugin Manger
  13. Choose Gonpp and install Gonpp

How to test?

  1. Open Notepad++
  2. Click Language -> Go
  3. Type like this. You can change whatever you want in the words that circle.

  4. Than save as to C:/Go/Golang or C:/Program file/Go/Golang.
  5. And named as 'test.go' and click save.
  6. After that press "Alt+R"
  7. And...... Voila!
 --------------------------------------------------------------------------------------------------------------------------------

Sorry if my grammar full of mistakes

#CMIIW

----------------------------------------------------------------------------------------------------------------------------------
Big thank's for Github & many blogger