Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8101251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:56:18+00:00 2026-06-05T22:56:18+00:00

I was surprised to find that Go has a ‘goto’ statement. I’ve always been

  • 0

I was surprised to find that Go has a ‘goto’ statement. I’ve always been taught that ‘goto’ statements are a thing of the past and evil for it occludes the actual flow of a program, and that functions or methods are always a better way of controlling flow.

I must be missing something. Why did Google include it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:56:20+00:00Added an answer on June 5, 2026 at 10:56 pm

    When we actually check the source code of the Go standard library, we can see where gotos are actually well applied.

    For example, in the math/gamma.go file, the goto statement is used:

      for x < 0 {
        if x > -1e-09 {
          goto small
        }
        z = z / x
        x = x + 1
      }
      for x < 2 {
        if x < 1e-09 {
          goto small
        }
        z = z / x
        x = x + 1
      }
    
      if x == 2 {
        return z
      }
    
      x = x - 2
      p = (((((x*_gamP[0]+_gamP[1])*x+_gamP[2])*x+_gamP[3])*x+_gamP[4])*x+_gamP[5])*x + _gamP[6]
      q = ((((((x*_gamQ[0]+_gamQ[1])*x+_gamQ[2])*x+_gamQ[3])*x+_gamQ[4])*x+_gamQ[5])*x+_gamQ[6])*x + _gamQ[7]
      return z * p / q
    
    small:
      if x == 0 {
        return Inf(1)
      }
      return z / ((1 + Euler*x) * x)
    }
    

    The goto in this case saves us from introducing another (boolean) variable used just for control-flow, checked for at the end. In this case, the goto statement makes the code actually better to read and easier follow (quite in contrary to the argument against goto you mentioned).

    Also note, that the goto statement has a very specific use-case. The language specification on goto states that it may not jump over variables coming into scope (being declared), and it may not jump into other (code-)blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Surprised that i havent been able to find this myself, but anyway. Let's say
I was surprised to find that the following code System.out.println("Character size:"+Character.SIZE/8); System.out.println("String size:"+"a".getBytes().length); outputs
I'm quite surprised I haven't been able to find out what characters I need
I'm surprised that MS has implemented a new feature: Validation with INotifyDataErrorInfo I have
I was somewhat surprised to find that std::shared_ptr provides no protection (eg, throw an
I'm surprised I haven’t been able to find the solution floating around online. There
I'm quite surprised that Google didn't find a solution. I'm searching for a solution
Surprised this question has not been asked yet here, but here goes: Serialization in
I have been working on a project that has common bits of functionality, specifically
I'm a bit surprised to find the results of the following code, where I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.