book icon indicating copy to clipboard operation
book copied to clipboard

Fixed ch03-05-control-flow.md, replaced `for` with `while`

Open Atabic opened this issue 2 years ago • 6 comments

Hi team, The section heading was Looping Through a Collection with for and instead the explanation under it is about while. Updated a link in ch12 which caused one of the job to fail

Atabic avatar Oct 26 '23 12:10 Atabic

Hi @carols10cents . Can you please review this whenever you get time?

Atabic avatar Oct 26 '23 12:10 Atabic

Please read that section again. It starts by explaining looping over a collection with the previously introduced while loop. Then it tells you there is a much better way by using for. So this section heading is correct.

RafaelKr avatar Oct 27 '23 09:10 RafaelKr

@RafaelKr But the section under it explains all about how to loop over a collection using while instead of for. image

Atabic avatar Oct 27 '23 09:10 Atabic

Yes, but it does it to explain why using a while in this case isn't as good as for.

To be fair I read this very section the first time 2 hours ago and also wondered why it is labelled for and starts with a code block about a while loop. But after reading the section, things cleared up for me.

My suggestion is to update the wording of the first sentence instead:

- You can choose to use the while construct to loop over the elements of a collection
+ You could choose to use the while construct to loop over the elements of a collection

So changing can to could. This makes it clearer that while is a way to do it, but for is much better as explained later starting at However, this approach [using a while loop] is error prone; we could cause the program to panic if the index value or test condition is incorrect...

RafaelKr avatar Oct 27 '23 09:10 RafaelKr

@Atabic I just created #3758 with my suggestion.

RafaelKr avatar Oct 27 '23 12:10 RafaelKr

Closing in favor of #3758. The heading order here is intentional, but that small wording tweak should help. Thanks!

chriskrycho avatar Mar 27 '24 18:03 chriskrycho