Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested correction to explanatory text for exercise 14 #9

Closed
SRNissen opened this issue Jun 26, 2023 · 2 comments · Fixed by #12
Closed

Suggested correction to explanatory text for exercise 14 #9

SRNissen opened this issue Jun 26, 2023 · 2 comments · Fixed by #12

Comments

@SRNissen
Copy link
Contributor

SRNissen commented Jun 26, 2023

The current text is technically false. As of today, it is written:

// Problem:
// For statements can also have init and post statements in the clause.
//
//  for i := 0; i <= 10; i = i + 1 {
//      fmt.Println(i)
//  }
//
// The above for loop will iterate from 0 to 10 and is
// identical in functionality to the following
// single-condition for statement:
//
//  i := 0
//  for i <= 10 {
//      fmt.Println(i)
//      i = i + 1
//  }

which would leave i in scope after the loop block, which is true in some languages but not here.

Proposed change

The exercise text could instead be

// Problem:
// For statements can also have init and post statements in the clause.
//
//  for i := 0; i <= 10; i = i + 1 {
//      fmt.Println(i)
//  }
//
// The above for loop will iterate from 0 to 10 and is
// identical in functionality to the following
// single-condition for statement:
//
// {
//      i := 0
//      for i <= 10 {
//          fmt.Println(i)
//          i = i + 1
// }
@soypat
Copy link
Owner

soypat commented Jun 26, 2023

I'm a bit on the fence with the idea of adding anonymous scopes as that is a feature that may catch some off guard. Maybe we can change the comment:

// The above for loop will iterate from 0 to 10.
// The following single-condition for statement
// will also perform the same operations:

This sound good?

@SRNissen
Copy link
Contributor Author

It does

SRNissen added a commit to SRNissen/gopherlings that referenced this issue Jun 26, 2023
The two loops are not quite the same (the scope of var i is different) so let's avoid telling beginning learners that they are "identical"
soypat pushed a commit that referenced this issue Jun 26, 2023
* Issue #9 Correction to explanatory text

The two loops are not quite the same (the scope of var i is different) so let's avoid telling beginning learners that they are "identical"

* #10 I am still going

Added comment "// I AM STILL GOING" for the "gopherlings watch" program

* #11 Gopherlings watch skips past exercises 031 and 032
@soypat soypat linked a pull request Jun 26, 2023 that will close this issue
@soypat soypat closed this as completed Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants