* remove "\r" nonsense
[mascara-docs.git] / C / the.ansi.c.programming.language / notes.accompany.ansi.c / sx4g.html
blobaa8cbcaea958ec19f147c580b9c1d5ee6ed80818
1 <!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
5 <html>
6 <head>
7 <link rev="owner" href="mailto:scs@eskimo.com">
8 <link rev="made" href="mailto:scs@eskimo.com">
9 <title>section 1.5.2: Character Counting</title>
10 <link href="sx4f.html" rev=precedes>
11 <link href="sx4h.html" rel=precedes>
12 <link href="sx4.html" rev=subdocument>
13 </head>
14 <body>
15 <H2>section 1.5.2: Character Counting</H2>
17 page 18
18 <p>Ignore the mention of efficiency with respect to
19 <TT>nc = nc+1</TT> vs. <TT>++nc</TT>.
20 Once you've gotten used to <TT>++</TT> meaning ``increment by 1,''
21 you'll probably find yourself preferring <TT>++nc</TT>
22 simply because it is more concise,
23 and incrementing things by 1 is so common.
24 (Personally,
25 once I got used to it,
26 I found <TT>++</TT> more natural, too,
27 because after all,
28 expressions like <TT>nc = nc+1</TT>,
29 though they're common enough in programming,
30 are very unnatural from an algebraic perspective.)
31 </p><p>pages 18-19
32 </p><p>You may find it odd to have a loop with no body,
33 but such loops do crop up.
34 Just make sure that the explicit null statement
35 (or, if you prefer, empty <TT>{}</TT>)
36 marking the empty loop body is plainly visible.
37 </p><p>The whole first paragraph of page 19 counts as ``deep.''
38 A clean, well-designed loop will work properly for all of its
39 ``boundary conditions'':
40 zero trips through the loop,
41 one trip,
42 many trips,
43 maximum trips
44 (if there is any maximum,
45 and if so, also maximum minus one).
46 If a loop for some reason doesn't work at a particular boundary condition,
47 it's tempting to claim that that condition is rare or
48 impossible and that the loop is therefore okay.
49 But if
50 the loop
51 can't handle
52 the boundary condition,
53 why can't it?
54 It's probably awkwardly constructed,
55 and straightening it out so
56 that it naturally handles all boundary conditions
57 will usually make it clearer and easier to understand
58 (and may also remove other lurking bugs).
59 </p><hr>
60 <p>
61 Read sequentially:
62 <a href="sx4f.html" rev=precedes>prev</a>
63 <a href="sx4h.html" rel=precedes>next</a>
64 <a href="sx4.html" rev=subdocument>up</a>
65 <a href="top.html">top</a>
66 </p>
67 <p>
68 This page by <a href="http://www.eskimo.com/~scs/">Steve Summit</a>
69 // <a href="copyright.html">Copyright</a> 1995, 1996
70 // <a href="mailto:scs@eskimo.com">mail feedback</a>
71 </p>
72 </body>
73 </html>