Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

GoLang– Break use cases

Break is used to exit from the loop.

Use Case 1:

package main  

import “fmt”  

func main() {  

   var  a int = 1  

   for a 

      fmt.Print(“Value of a is “,a,”\n”)  

      a++;  

      if a > 5{  

         /* terminate the loop using break statement */  

         break;  

      }  

   }  

}  

Output:

Use Case 2:

package main  

import “fmt”  

func main() {  

   var a int  

   var b int  

   for a = 1; a 

      for b = 1; b 

fmt.Println(“Prwatech”)

         if (a == 2 && b == 2) {  

            break;  

         }  

         fmt.Print(a, ” “, b, “\n”)  

     }  

   }  

}  

Output:

Use Case 3:

package main  

import “fmt”  

func main() {  

   var a int  

   var b int  

   for a = 1; a 

      for b = 1; b 

        if (a % 2 == 0) {  

            break;  

         }  

         fmt.Print(a, ” “, b, “\n”)  

     }  

   }  

}  

Output:

The post GoLang– Break use cases appeared first on Prwatech.



This post first appeared on Learn Big Data Hadoop In Bangalore, please read the originial post: here

Share the post

GoLang– Break use cases

×

Subscribe to Learn Big Data Hadoop In Bangalore

Get updates delivered right to your inbox!

Thank you for your subscription

×