Solution: Introduction to Go
Let’s solve the challenges set in the previous lesson.
We'll cover the following
Problem 1: Solution
To find all possible occurrences of the desired executable, we can make the following changes to the which.go
code:
Declare a
results
variable of type[]string
to store all the full paths of the executable.Inside the
for
loop, after finding an executable, instead of returning immediately, append the full path of the executable to theresults
variable.After the first
for
loop, use anotherfor
loop to iterate over theresults
variable and print all the full paths.Remove the
return
statement at the end of thefor
loop.
Here is an example of the updated code:
Get hands-on with 1400+ tech skills courses.