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 7786769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:28:30+00:00 2026-06-01T20:28:30+00:00

When I tried to print out: fmt.Println(c <- x) right before the for loop

  • 0

When I tried to print out:

fmt.Println(c <- x)

right before the for loop in the code block below to see what “c <- x” would evaluate to, it got the error message:

./select.go:7: send statement c <- x used as value; use select for non-blocking send

Is “c <- x” evaluated to true if the sending operation was successful? And why does Go only let you use the value of the send statement (aka value of “c <- x”) inside case statements inside a select statement?

    func fibonacci(c, quit chan int) {
        x, y := 1, 1

        for {
            select {
            case c <- x:
                x, y = y, x + y
            case <-quit:
                fmt.Println("quit")
                return
            }
        }
    }

Thank you

  • 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-01T20:28:31+00:00Added an answer on June 1, 2026 at 8:28 pm

    It’s true, c <- x is a statement and has no value.

    You may be confusing select with switch. Switch works by seeing which case expression matches or evaluates to true. Select, on the other hand, looks for cases which are not blocking, picks one of them to allow to proceed, and then runs the statements in the case block.

    So no, c <- x is not evaluated to true wen the sending operation is successful. Instead, the statement of the case block, x, y = y, x + y
    is simply executed. There is no result of a send, no true value, stored anywhere.

    You may have read that for a receive operation, a variable assigned with a short declarion is only in the scope of the case block. This is true (although there are no short declarations in the cases of the select statement above.) If you had a case where you wanted a received value after the case block ends, you would use a simple assignment and not a short declaration.

    Oblig: the language spec on the select statement. It’s really very readable.

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

Sidebar

Related Questions

I've seen some code such as: out.println(print something); I tried import java.lang.System; but it's
I got the above error and tried to print out the object to see
I'm using the following code to loop through a directory to print out the
in c, i tried to print out address of variable and address of some
I'm having trouble making python print out texts properly aligned. I have tried everything
I would like to print out the data, for debugging purpose. Data format would
The following is tried to print out N number of spaces (or 12 in
I would like to use echo in bash to print out a string of
Using scanf, each number typed in, i would like my program to print out
Today out of curiosity, i tried something very weird: The Code : int num

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.