additions to hello world - provided addition for loop implementation

This commit is contained in:
Perry Kivolowitz 2024-02-05 10:54:54 -06:00
parent d9f4ff4c17
commit 29791113ae

View file

@ -170,7 +170,7 @@ Somewhere inside the body of the loop, the value of `argv` will be
changed. If it were not, the loop would not terminate (i.e. an *infinite
loop*).
#### Line 6 could be redone as a `for` loop
#### Line 6 could be redone as a `for` loop in more than one way
`Line 6` in this case could have been written using a `for` loop:
@ -186,6 +186,15 @@ of `argv` is examined in each loop. We claim `index` is unneeded in this
case as we have a different way of moving through the `argv` array and,
most importantly, knowing when to stop.
Or, it could have been rewritten as a `for` loop in this way:
```c++
for (; argv; argv++)
```
which is almost identical to the `while` version with added benefit that
the increment of the `argv` pointer is not a side effect.
### Line 7
`Line 7` is where the action is. Firstly, `cout` will receive some value
@ -237,6 +246,10 @@ but this comes at the expense of maintainability.
So, do as we say, not as we did.
Putting the increment on its own line will make it more clear and remove
it as a side effect making the code more maintainable. Or, you could use
the `for` construction described [earlier](#line-6-could-be-redone-as-a-for-loop-in-more-than-one-way).
### Line 8
`Line 8` contains a matching brace for the opening brace found line