* remove "\r" nonsense
[mascara-docs.git] / C / the.ansi.c.programming.language / c.programming.notes / sx14c.html
blobcc6dc9fa16dec8af0b3b225bc3b833c3ade3abcc
1 <!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995-7 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>Statements</title>
10 <link href="sx14b.html" rev=precedes>
11 <link href="sx14d.html" rel=precedes>
12 <link href="sx14.html" rev=subdocument>
13 </head>
14 <body>
15 <H2>Statements</H2>
17 <p>The <TT>switch</TT> statement allows you to jump to one of a
18 number of numeric <TT>case</TT> labels depending on the value of
19 an expression;
20 it's more convenient than a long <TT>if</TT>/<TT>else</TT> chain.
21 (However, you can use <TT>switch</TT>
22 only when the expression is integral
23 and all of the <TT>case</TT> labels are compile-time constants.)
24 </p><p>The <TT>do</TT>/<TT>while</TT> loop
25 is a loop that tests its controlling expression
26 at the bottom of the loop,
27 so that the body of the loop always executes once
28 even if the condition is initially false.
29 (C's <TT>do</TT>/<TT>while</TT> loop is therefore like
30 Pascal's <TT>repeat</TT>/<TT>until</TT> loop,
31 while
33 C's <TT>while</TT> loop is like Pascal's <TT>while</TT>/<TT>do</TT> loop.)
34 </p><p>Finally,
35 when you really need to write ``spaghetti code,''
36 C does have the all-purpose <TT>goto</TT> statement,
37 and labels to go to.
38 </p><hr>
39 <p>
40 Read sequentially:
41 <a href="sx14b.html" rev=precedes>prev</a>
42 <a href="sx14d.html" rel=precedes>next</a>
43 <a href="sx14.html" rev=subdocument>up</a>
44 <a href="top.html">top</a>
45 </p>
46 <p>
47 This page by <a href="http://www.eskimo.com/~scs/">Steve Summit</a>
48 // <a href="copyright.html">Copyright</a> 1995-1997
49 // <a href="mailto:scs@eskimo.com">mail feedback</a>
50 </p>
51 </body>
52 </html>