|
77 | 77 | \pnum
|
78 | 78 | \indextext{\idxgram{condition}{s}!rules for}%
|
79 | 79 | The rules for \grammarterm{condition}{s} apply both to
|
80 |
| -\grammarterm{selection-statement}{s} and to the \tcode{for} and \tcode{while} |
| 80 | +\grammarterm{selection-statement}{s} and to the \keyword{for} and \keyword{while} |
81 | 81 | statements\iref{stmt.iter}.
|
82 | 82 | A \grammarterm{condition} that is not an \grammarterm{expression} is a
|
83 | 83 | declaration\iref{dcl.dcl}.
|
|
89 | 89 |
|
90 | 90 | \pnum
|
91 | 91 | The value of a \grammarterm{condition} that is an initialized declaration
|
92 |
| -in a statement other than a \tcode{switch} statement is the value of the |
| 92 | +in a statement other than a \keyword{switch} statement is the value of the |
93 | 93 | declared variable
|
94 | 94 | contextually converted to \tcode{bool}\iref{conv}.
|
95 | 95 | If that
|
96 | 96 | conversion is ill-formed, the program is ill-formed. The value of a
|
97 | 97 | \grammarterm{condition} that is an initialized declaration in a
|
98 |
| -\tcode{switch} statement is the value of the declared variable if it has |
| 98 | +\keyword{switch} statement is the value of the declared variable if it has |
99 | 99 | integral or enumeration type, or of that variable implicitly converted
|
100 | 100 | to integral or enumeration type otherwise. The value of a
|
101 | 101 | \grammarterm{condition} that is an expression is the value of the
|
102 | 102 | expression, contextually converted to \tcode{bool}
|
103 | 103 | for statements other
|
104 |
| -than \tcode{switch}; |
| 104 | +than \keyword{switch}; |
105 | 105 | if that conversion is ill-formed, the program is
|
106 | 106 | ill-formed. The value of the condition will be referred to as simply
|
107 | 107 | ``the condition'' where the usage is unambiguous.
|
|
143 | 143 | \pnum
|
144 | 144 | \indextext{label!\idxcode{case}}%
|
145 | 145 | \indextext{label!\idxcode{default}}%
|
146 |
| -Case labels and default labels shall occur only in \tcode{switch} statements. |
| 146 | +Case labels and default labels shall occur only in \keyword{switch} statements. |
147 | 147 |
|
148 | 148 |
|
149 | 149 | \rSec1[stmt.expr]{Expression statement}%
|
|
170 | 170 | Most statements are expression statements --- usually assignments or
|
171 | 171 | function calls. A null statement is useful to carry a label just before
|
172 | 172 | the \tcode{\}} of a compound statement and to supply a null body to an
|
173 |
| -iteration statement such as a \tcode{while} |
| 173 | +iteration statement such as a \keyword{while} |
174 | 174 | statement\iref{stmt.while}.
|
175 | 175 | \end{note}
|
176 | 176 |
|
|
233 | 233 |
|
234 | 234 | \pnum
|
235 | 235 | If the condition\iref{stmt.select} yields \tcode{true} the first
|
236 |
| -substatement is executed. If the \tcode{else} part of the selection |
| 236 | +substatement is executed. If the \keyword{else} part of the selection |
237 | 237 | statement is present and the condition yields \tcode{false}, the second
|
238 | 238 | substatement is executed. If the first substatement is reached via a
|
239 | 239 | label, the condition is not evaluated and the second substatement is
|
240 |
| -not executed. In the second form of \tcode{if} statement |
241 |
| -(the one including \tcode{else}), if the first substatement is also an |
242 |
| -\tcode{if} statement then that inner \tcode{if} statement shall contain |
243 |
| -an \tcode{else} part. |
| 240 | +not executed. In the second form of \keyword{if} statement |
| 241 | +(the one including \keyword{else}), if the first substatement is also an |
| 242 | +\keyword{if} statement then that inner \tcode{if} statement shall contain |
| 243 | +an \keyword{else} part. |
244 | 244 | \begin{footnote}
|
245 |
| -In other words, the \tcode{else} is associated with the nearest un-elsed |
246 |
| -\tcode{if}. |
| 245 | +In other words, the \keyword{else} is associated with the nearest un-elsed |
| 246 | +\keyword{if}. |
247 | 247 | \end{footnote}
|
248 | 248 |
|
249 | 249 | \pnum
|
250 |
| -If the \tcode{if} statement is of the form \tcode{if constexpr}, the value |
| 250 | +If the \keyword{if} statement is of the form \tcode{if constexpr}, the value |
251 | 251 | of the condition shall be a contextually
|
252 | 252 | converted constant expression of type \tcode{bool}\iref{expr.const}; this
|
253 | 253 | form is called a \defn{constexpr if} statement. If the value of the
|
|
261 | 261 | Odr-uses\iref{basic.def.odr} in a discarded statement do not require
|
262 | 262 | an entity to be defined.
|
263 | 263 | \end{note}
|
264 |
| -A \tcode{case} or \tcode{default} label appearing within such an |
265 |
| -\tcode{if} statement shall be associated with a \tcode{switch} |
266 |
| -statement\iref{stmt.switch} within the same \tcode{if} statement. |
| 264 | +A \keyword{case} or \keyword{default} label appearing within such an |
| 265 | +\keyword{if} statement shall be associated with a \keyword{switch} |
| 266 | +statement\iref{stmt.switch} within the same \keyword{if} statement. |
267 | 267 | A label\iref{stmt.label} declared in a substatement of a constexpr if
|
268 | 268 | statement shall only be referred to by a statement\iref{stmt.goto} in
|
269 | 269 | the same substatement.
|
|
290 | 290 | \end{example}
|
291 | 291 |
|
292 | 292 | \pnum
|
293 |
| -An \tcode{if} statement of the form |
| 293 | +An \keyword{if} statement of the form |
294 | 294 | \begin{ncsimplebnf}
|
295 | 295 | \keyword{if} \opt{\keyword{constexpr}} \terminal{(} init-statement condition \terminal{)} statement
|
296 | 296 | \end{ncsimplebnf}
|
|
301 | 301 | \bnfindent \keyword{if} \opt{\keyword{constexpr}} \terminal{(} condition \terminal{)} statement\br
|
302 | 302 | \terminal{\}}
|
303 | 303 | \end{ncsimplebnf}
|
304 |
| -and an \tcode{if} statement of the form |
| 304 | +and an \keyword{if} statement of the form |
305 | 305 | \begin{ncsimplebnf}
|
306 | 306 | \keyword{if} \opt{\keyword{constexpr}} \terminal{(} init-statement condition \terminal{)} statement \keyword{else} statement
|
307 | 307 | \end{ncsimplebnf}
|
|
319 | 319 | \indextext{statement!\idxcode{switch}}
|
320 | 320 |
|
321 | 321 | \pnum
|
322 |
| -The \tcode{switch} statement causes control to be transferred to one of |
| 322 | +The \keyword{switch} statement causes control to be transferred to one of |
323 | 323 | several statements depending on the value of a condition.
|
324 | 324 |
|
325 | 325 | \pnum
|
|
331 | 331 | promotions\iref{conv.prom}, the condition is converted
|
332 | 332 | to the promoted type.
|
333 | 333 | Any
|
334 |
| -statement within the \tcode{switch} statement can be labeled with one or |
| 334 | +statement within the \keyword{switch} statement can be labeled with one or |
335 | 335 | more case labels as follows:
|
336 | 336 | \begin{ncbnf}
|
337 | 337 | \indextext{label!\idxcode{case}}%
|
|
348 | 348 | \begin{codeblock}
|
349 | 349 | default :
|
350 | 350 | \end{codeblock}
|
351 |
| -within a \tcode{switch} statement. |
| 351 | +within a \keyword{switch} statement. |
352 | 352 |
|
353 | 353 | \pnum
|
354 |
| -Switch statements can be nested; a \tcode{case} or \tcode{default} label |
| 354 | +Switch statements can be nested; a \keyword{case} or \keyword{default} label |
355 | 355 | is associated with the smallest switch enclosing it.
|
356 | 356 |
|
357 | 357 | \pnum
|
358 |
| -When the \tcode{switch} statement is executed, its condition is |
| 358 | +When the \keyword{switch} statement is executed, its condition is |
359 | 359 | evaluated.
|
360 | 360 | \indextext{label!\idxcode{case}}%
|
361 | 361 | If one of the case constants has the same value as the condition,
|
362 | 362 | control is passed to the statement following the matched case label. If
|
363 | 363 | no case constant matches the condition, and if there is a
|
364 | 364 | \indextext{label!\idxcode{default}}%
|
365 |
| -\tcode{default} label, control passes to the statement labeled by the |
366 |
| -default label. If no case matches and if there is no \tcode{default} |
| 365 | +\keyword{default} label, control passes to the statement labeled by the |
| 366 | +default label. If no case matches and if there is no \keyword{default} |
367 | 367 | then none of the statements in the switch is executed.
|
368 | 368 |
|
369 | 369 | \pnum
|
370 |
| -\tcode{case} and \tcode{default} labels in themselves do not alter the |
| 370 | +\keyword{case} and \keyword{default} labels in themselves do not alter the |
371 | 371 | flow of control, which continues unimpeded across such labels. To exit
|
372 |
| -from a switch, see \tcode{break}, \ref{stmt.break}. |
| 372 | +from a switch, see \keyword{break}, \ref{stmt.break}. |
373 | 373 | \begin{note}
|
374 | 374 | Usually, the substatement that is the subject of a switch is compound
|
375 |
| -and \tcode{case} and \tcode{default} labels appear on the top-level |
| 375 | +and \keyword{case} and \keyword{default} labels appear on the top-level |
376 | 376 | statements contained within the (compound) substatement, but this is not
|
377 | 377 | required.
|
378 | 378 | \indextext{statement!declaration in \tcode{switch}}%
|
379 | 379 | Declarations can appear in the substatement of a
|
380 |
| -\tcode{switch} statement. |
| 380 | +\keyword{switch} statement. |
381 | 381 | \end{note}
|
382 | 382 |
|
383 | 383 | \pnum
|
384 |
| -A \tcode{switch} statement of the form |
| 384 | +A \keyword{switch} statement of the form |
385 | 385 | \begin{ncsimplebnf}
|
386 | 386 | \keyword{switch} \terminal{(} init-statement condition \terminal{)} statement
|
387 | 387 | \end{ncsimplebnf}
|
|
454 | 454 | int i;
|
455 | 455 | }
|
456 | 456 | \end{codeblock}
|
457 |
| -Thus after the \tcode{while} statement, \tcode{i} is no longer in scope. |
| 457 | +Thus after the \keyword{while} statement, \tcode{i} is no longer in scope. |
458 | 458 | \end{example}
|
459 | 459 |
|
460 | 460 | \rSec2[stmt.while]{The \tcode{while} statement}%
|
461 | 461 | \indextext{statement!\idxcode{while}}
|
462 | 462 |
|
463 | 463 | \pnum
|
464 |
| -In the \tcode{while} statement the substatement is executed repeatedly |
| 464 | +In the \keyword{while} statement the substatement is executed repeatedly |
465 | 465 | until the value of the condition\iref{stmt.select} becomes
|
466 | 466 | \tcode{false}. The test takes place before each execution of the
|
467 | 467 | substatement.
|
468 | 468 |
|
469 | 469 | \pnum
|
470 | 470 | \indextext{statement!declaration in \tcode{while}}%
|
471 |
| -A \tcode{while} statement is equivalent to |
| 471 | +A \keyword{while} statement is equivalent to |
472 | 472 | \begin{ncsimplebnf}
|
473 | 473 | \exposid{label} \terminal{:}\br
|
474 | 474 | \terminal{\{}\br
|
|
509 | 509 | if that conversion is ill-formed, the program is ill-formed.
|
510 | 510 |
|
511 | 511 | \pnum
|
512 |
| -In the \tcode{do} statement the substatement is executed repeatedly |
| 512 | +In the \keyword{do} statement the substatement is executed repeatedly |
513 | 513 | until the value of the expression becomes \tcode{false}. The test takes
|
514 | 514 | place after each execution of the statement.
|
515 | 515 |
|
516 | 516 | \rSec2[stmt.for]{The \tcode{for} statement}%
|
517 | 517 | \indextext{statement!\idxcode{for}}
|
518 | 518 |
|
519 | 519 | \pnum
|
520 |
| -The \tcode{for} statement |
| 520 | +The \keyword{for} statement |
521 | 521 | \begin{ncsimplebnf}
|
522 | 522 | \keyword{for} \terminal{(} init-statement \opt{condition} \terminal{;} \opt{expression} \terminal{)} statement
|
523 | 523 | \end{ncsimplebnf}
|
|
535 | 535 | in the same scope as the \grammarterm{condition}, and
|
536 | 536 | except that a
|
537 | 537 | \indextext{statement!\tcode{continue} in \tcode{for}}%
|
538 |
| -\tcode{continue} in \grammarterm{statement} (not enclosed in another |
| 538 | +\keyword{continue} in \grammarterm{statement} (not enclosed in another |
539 | 539 | iteration statement) will execute \grammarterm{expression} before
|
540 | 540 | re-evaluating \grammarterm{condition}.
|
541 | 541 | \begin{note}
|
|
550 | 550 | Either or both of the \grammarterm{condition}
|
551 | 551 | and the \grammarterm{expression} can be omitted.
|
552 | 552 | A missing \grammarterm{condition}
|
553 |
| -makes the implied \tcode{while} clause |
| 553 | +makes the implied \keyword{while} clause |
554 | 554 | equivalent to \tcode{while(true)}.
|
555 | 555 |
|
556 | 556 | \rSec2[stmt.ranged]{The range-based \tcode{for} statement}%
|
557 | 557 | \indextext{statement!range based for@range based \tcode{for}}
|
558 | 558 |
|
559 | 559 | \pnum
|
560 |
| -The range-based \tcode{for} statement |
| 560 | +The range-based \keyword{for} statement |
561 | 561 | \begin{ncsimplebnf}
|
562 | 562 | \keyword{for} \terminal{(} \opt{init-statement} for-range-declaration \terminal{:} for-range-initializer \terminal{)} statement
|
563 | 563 | \end{ncsimplebnf}
|
|
679 | 679 | \indextext{statement!\idxcode{break}}
|
680 | 680 |
|
681 | 681 | \pnum
|
682 |
| -The \tcode{break} statement shall occur only in an |
| 682 | +The \keyword{break} statement shall occur only in an |
683 | 683 | \indextext{\idxgram{iteration-statement}}%
|
684 | 684 | \indextext{statement!\idxcode{switch}}%
|
685 |
| -\grammarterm{iteration-statement} or a \tcode{switch} statement and causes |
| 685 | +\grammarterm{iteration-statement} or a \keyword{switch} statement and causes |
686 | 686 | termination of the smallest enclosing \grammarterm{iteration-statement} or
|
687 |
| -\tcode{switch} statement; control passes to the statement following the |
| 687 | +\keyword{switch} statement; control passes to the statement following the |
688 | 688 | terminated statement, if any.
|
689 | 689 |
|
690 | 690 | \rSec2[stmt.cont]{The \tcode{continue} statement}%
|
691 | 691 | \indextext{statement!\idxcode{continue}}
|
692 | 692 |
|
693 | 693 | \pnum
|
694 | 694 | The
|
695 |
| -\tcode{continue} |
| 695 | +\keyword{continue} |
696 | 696 | statement shall occur only in an
|
697 | 697 | \indextext{\idxgram{iteration-statement}}%
|
698 | 698 | \grammarterm{iteration-statement}
|
|
731 | 731 | \end{codeblock}
|
732 | 732 | \end{minipage}
|
733 | 733 |
|
734 |
| -a \tcode{continue} not contained in an enclosed iteration statement is |
| 734 | +a \keyword{continue} not contained in an enclosed iteration statement is |
735 | 735 | equivalent to \tcode{goto} \exposid{contin}.
|
736 | 736 |
|
737 | 737 | \rSec2[stmt.return]{The \tcode{return} statement}%
|
|
893 | 893 | unless all such variables have vacuous initialization\iref{basic.life},
|
894 | 894 | the transfer of control shall not be a jump.
|
895 | 895 | \begin{footnote}
|
896 |
| -The transfer from the condition of a \tcode{switch} statement to a |
897 |
| -\tcode{case} label is considered a jump in this respect. |
| 896 | +The transfer from the condition of a \keyword{switch} statement to a |
| 897 | +\keyword{case} label is considered a jump in this respect. |
898 | 898 | \end{footnote}
|
899 | 899 | When a \grammarterm{declaration-statement} is executed,
|
900 | 900 | $P$ and $Q$ are the points immediately before and after it;
|
|
0 commit comments