Skip to content

Commit 7a796e0

Browse files
Manual changes for suggestions on code review
1 parent cfe838d commit 7a796e0

File tree

11 files changed

+37
-41
lines changed

11 files changed

+37
-41
lines changed

concepts/for-loops/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"andrerfcsantos"
66
],
77
"contributors": []
8-
}
8+
}

concepts/for-loops/about.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ for i := 1; i < 10; i++ {
2626
}
2727
```
2828

29-
This loop will print the numbers from `1` to `9` inclusivé.
29+
This loop will print the numbers from `1` to `9` (including `9`).
3030
Defining the step is often done using an increment or decrement statement, as shown in the example above.
3131

3232
## Optional components of the header
@@ -87,7 +87,7 @@ for {
8787
}
8888
```
8989

90-
This loop will never end and will only ever finish if the program exits or has a `break` in its body.
90+
This loop will only ever finish if the program exits or has a `break` in its body.
9191

9292
## Labels and goto
9393

concepts/for-loops/introduction.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
# Introduction
22

3+
34
## General syntax
45

5-
The for loop is one of the most commonly used statements to repeatedly execute some logic. In Go it consists of the `for` keyword, a header and a code block that contains the body of the loop wrapped in curly brackets. The header consists of 3 components separated by semicolons `;`: initilization, condition and step.
6+
The for loop is one of the most commonly used statements to repeatedly execute some logic. In Go it consists of the `for` keyword, a header and a code block that contains the body of the loop wrapped in curly brackets. The header consists of 3 components separated by semicolons `;`: init, condition and post.
67

78
```go
8-
for initialization; condition; step {
9+
for init; condition; post {
910
// loop body - code that is executed repeatedly as long as the condition is true
1011
}
1112
```
1213

13-
- The **initialization** component is some code that runs only once before the loop starts.
14+
- The **init** component is some code that runs only once before the loop starts.
1415
- The **condition** component must be some expression that evaluates to a boolean and controls when the loop should stop. The code inside the loop will run as long as this condition evaluates to true. As soon as this expression evaluates to false, no more iterations of the loop will run.
15-
- The **step** component is some code that will run at the end of each iteration.
16+
- The **post** component is some code that will run at the end of each iteration.
1617

1718
**Note:** Unlike other languages, there are no parentheses `()` surrounding the three components of the header. In fact, inserting such parenthesis is a compilation error. However, the braces `{ }` surrounding the loop body are always required.
1819

1920
## For Loops - An example
2021

21-
The initialization component usually sets up a counter variable, the condition checks whether the loop should be continued or stopped and the step increments the counter at the end of each repetition.
22+
The init component usually sets up a counter variable, the condition checks whether the loop should be continued or stopped and the post component usually increments the counter at the end of each repetition.
2223

2324
```go
2425
for i := 1; i < 10; i++ {
2526
fmt.Println(i)
2627
}
2728
```
2829

29-
This loop will print the numbers from `1` to `9` inclusivé.
30+
This loop will print the numbers from `1` to `9` (including `9`).
3031
Defining the step is often done using an increment or decrement statement, as shown in the example above.

concepts/for-loops/links.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"url": "https://yourbasic.org/golang/for-loop/",
1212
"description": "Article: 5 basic for loop patterns"
1313
}
14-
]
14+
]

exercises/concept/bird-watcher/.docs/hints.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
## 1. Determine the total number of birds that you counted so far
44

5-
- Refer to the exercise introduction for an example how to use a for loop to iterate over an array.
6-
- Use a helper variable to store the total count and increase that variable as you go through the array.
5+
- Refer to the exercise introduction for an example how to use a for loop to iterate over a slice.
6+
- Use a helper variable to store the total count and increase that variable as you go through the slice.
77
- Think about the correct initial value for that helper variable.
88

99
## 2. Calculate the number of visiting birds in a specific week
1010

1111
- This task is similar to the first one, you can copy your code as a starting point.
12-
- Think about which indexes in the array you would need to take into account for week number 1 and 2, respectively.
12+
- Think about which indexes in the slice you would need to take into account for week number 1 and 2, respectively.
1313
- Now find a general way to calculate the first and the last index that should be considered.
14-
- With that you can set up the for loop to only iterate over the relevant section of the array.
14+
- With that you can set up the for loop to only iterate over the relevant section of the slice.
1515

1616
## 3. Fix a counting mistake
1717

18-
- Again you need to set up a for loop to iterate over the whole bird count array.
19-
- This time you only need to visit every second entry in the array.
18+
- Again you need to set up a for loop to iterate over the whole bird count slice.
19+
- This time you only need to visit every second entry in the slice.
2020
- Change the step so the counter variable is increased accordingly after each iteration.
21-
- In the body of the for loop you can use the increment operator to change the value of an element in an array in place.
21+
- In the body of the for loop you can use the increment operator to change the value of an element in a slice in-place.

exercises/concept/bird-watcher/.docs/instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TotalBirdCount(birdsPerDay)
2121

2222
Now that you got a general feel for your bird count numbers, you want to make a more fine-grained analysis.
2323

24-
Implement a function `BirdsInWeek` that accepts an array of bird counts per day and a week number.
24+
Implement a function `BirdsInWeek` that accepts a slice of bird counts per day and a week number.
2525

2626
It returns the total number of birds that you counted in that specific week.
2727
You can assume weeks are always tracked completely.
@@ -42,7 +42,7 @@ You do not know exactly where it was in between those days but definitely not in
4242

4343
Your bird watcher intuition also tells you that the bird was in your garden on the first day that you tracked in your list.
4444

45-
Given this new information, write a function `FixBirdCountLog` that takes an array of birds counted per day as an argument and returns an array after correcting the counting mistake.
45+
Given this new information, write a function `FixBirdCountLog` that takes a slice of birds counted per day as an argument and returns the slice after correcting the counting mistake.
4646

4747
```go
4848
var birdsPerDay []int = []int{2, 5, 0, 7, 4, 1}

exercises/concept/bird-watcher/.docs/introduction.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
## General syntax
44

5-
The for loop is one of the most commonly used statements to repeatedly execute some logic. In Go it consists of the `for` keyword, a header and a code block that contains the body of the loop wrapped in curly brackets. The header consists of 3 components separated by semicolons `;`: initilization, condition and step.
5+
The for loop is one of the most commonly used statements to repeatedly execute some logic. In Go it consists of the `for` keyword, a header and a code block that contains the body of the loop wrapped in curly brackets. The header consists of 3 components separated by semicolons `;`: init, condition and post.
66

77
```go
8-
for initialization; condition; step {
8+
for init; condition; post {
99
// loop body - code that is executed repeatedly as long as the condition is true
1010
}
1111
```
1212

13-
- The **initialization** component is some code that runs only once before the loop starts.
13+
- The **init** component is some code that runs only once before the loop starts.
1414
- The **condition** component must be some expression that evaluates to a boolean and controls when the loop should stop. The code inside the loop will run as long as this condition evaluates to true. As soon as this expression evaluates to false, no more iterations of the loop will run.
15-
- The **step** component is some code that will run at the end of each iteration.
15+
- The **post** component is some code that will run at the end of each iteration.
1616

1717
**Note:** Unlike other languages, there are no parentheses `()` surrounding the three components of the header. In fact, inserting such parenthesis is a compilation error. However, the braces `{ }` surrounding the loop body are always required.
1818

1919
## For Loops - An example
2020

21-
The initialization component usually sets up a counter variable, the condition checks whether the loop should be continued or stopped and the step increments the counter at the end of each repetition.
21+
The init component usually sets up a counter variable, the condition checks whether the loop should be continued or stopped and the post component usually increments the counter at the end of each repetition.
2222

2323
```go
2424
for i := 1; i < 10; i++ {
2525
fmt.Println(i)
2626
}
2727
```
2828

29-
This loop will print the numbers from `1` to `9` inclusivé.
29+
This loop will print the numbers from `1` to `9` (including `9`).
3030
Defining the step is often done using an increment or decrement statement, as shown in the example above.
3131

exercises/concept/bird-watcher/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
"forked_from": [
2121
"javascript/bird-watcher"
2222
]
23-
}
23+
}

exercises/concept/bird-watcher/.meta/exemplar.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package birdwatcher
22

33
// TotalBirdCount return the total bird count by summing
4-
// the individual day's counts
4+
// the individual day's counts.
55
func TotalBirdCount(birdsPerDay []int) int {
66
count := 0
77
for i := 0; i < len(birdsPerDay); i++ {
@@ -11,7 +11,7 @@ func TotalBirdCount(birdsPerDay []int) int {
1111
}
1212

1313
// BirdsInWeek returns the total bird count by summing
14-
// only the items belonging to the given week
14+
// only the items belonging to the given week.
1515
func BirdsInWeek(birdsPerDay []int, week int) int {
1616
count := 0
1717
startOfWeek := (week - 1) * 7
@@ -23,7 +23,7 @@ func BirdsInWeek(birdsPerDay []int, week int) int {
2323
}
2424

2525
// FixBirdCountLog returns the bird counts after correcting
26-
// the bird counts for alternate days
26+
// the bird counts for alternate days.
2727
func FixBirdCountLog(birdsPerDay []int) []int {
2828
for i := 0; i < len(birdsPerDay); i += 2 {
2929
birdsPerDay[i]++
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package birdwatcher
22

33
// TotalBirdCount return the total bird count by summing
4-
// the individual day's counts
4+
// the individual day's counts.
55
func TotalBirdCount(birdsPerDay []int) int {
66
panic("Please implement the TotalBirdCount() function")
77
}
88

99
// BirdsInWeek returns the total bird count by summing
10-
// only the items belonging to the given week
10+
// only the items belonging to the given week.
1111
func BirdsInWeek(birdsPerDay []int, week int) int {
1212
panic("Please implement the BirdsInWeek() function")
1313
}
1414

1515
// FixBirdCountLog returns the bird counts after correcting
16-
// the bird counts for alternate days
16+
// the bird counts for alternate days.
1717
func FixBirdCountLog(birdsPerDay []int) []int {
1818
panic("Please implement the FixBirdCountLog() function")
1919
}

0 commit comments

Comments
 (0)