Skip to content

Commit e64ccee

Browse files
authored
Update README.md
Fixed the C-style example at the start to use the prefix-increment instead of postfix-increment. (Yes, both versions 'do the same' if your hope that the compiler will optimise the use of a postfix-increment for you. Using a prefix-increment is good style as it is more clear what the intention of the statement is (which is to increment the iteration index, and not to increment but return the old value). Nonetheless, many programmers (including myself for many years) do not know about this, and many tutorials/explanations list the postfix-version. And this is of course exactly why iterator-based loops are so nice.
1 parent 7c32094 commit e64ccee

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cargo run
3636
Life is repetitive and most things in it come as series of items. Programmatically we often need to count, enumerate, and iterate over these sequences. There are several ways to generate repetition in programming languages. One of the most prominent constructs is C-style `for` loop with familiar syntax:
3737

3838
```c
39-
for ( x = 0; x < 10; x++ ) {
39+
for ( x = 0; x < 10; ++x ) {
4040
// do something
4141
}
4242
```

0 commit comments

Comments
 (0)