mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-21 02:26:59 +08:00
additions to hello world - provided addition for loop implementation
This commit is contained in:
parent
d9f4ff4c17
commit
29791113ae
1 changed files with 14 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue