I am working on a while loop which a for in Go as in below code
ele = path.Dir(str)
for ele != "." {
functionA()
ele = path.Dir(ele)
if ele == "." {
functionA()
functionB()
}
}
In the above code as you can see I am calling functionA twice based on a condition inside the while (for)
Is there a better and cleaner way to do this?
This is slightly different way to perform the same task.
UPDATE: Updated answer to reflect the new requirements.
ele := path.Dir(str)
if ele == "." {
return
}
for ele != "." {
functionA()
ele = path.Dir(ele)
}
functionA()
functionB()
Playground: https://play.golang.org/p/KbIH7s45aFR