|
296 | 296 |
|
297 | 297 | \pnum
|
298 | 298 | An \tcode{if} statement of the form
|
299 |
| - |
300 |
| -\begin{ncbnf} |
| 299 | +\begin{ncsimplebnf} |
301 | 300 | \terminal{if \opt{constexpr} (} init-statement condition \terminal{)} statement
|
302 |
| -\end{ncbnf} |
303 |
| - |
| 301 | +\end{ncsimplebnf} |
304 | 302 | is equivalent to
|
305 |
| - |
306 |
| -\begin{ncbnftab} |
| 303 | +\begin{ncsimplebnf} |
307 | 304 | \terminal{\{}\br
|
308 |
| -\>init-statement\br |
309 |
| -\>\terminal{if \opt{constexpr} (} condition \terminal{)} statement\br |
| 305 | +\bnfindent init-statement\br |
| 306 | +\bnfindent \terminal{if \opt{constexpr} (} condition \terminal{)} statement\br |
310 | 307 | \terminal{\}}
|
311 |
| -\end{ncbnftab} |
312 |
| - |
| 308 | +\end{ncsimplebnf} |
313 | 309 | and an \tcode{if} statement of the form
|
314 |
| - |
315 |
| -\begin{ncbnf} |
| 310 | +\begin{ncsimplebnf} |
316 | 311 | \terminal{if \opt{constexpr} (} init-statement condition \terminal{)} statement \terminal{else} statement
|
317 |
| -\end{ncbnf} |
318 |
| - |
| 312 | +\end{ncsimplebnf} |
319 | 313 | is equivalent to
|
320 |
| - |
321 |
| -\begin{ncbnftab} |
| 314 | +\begin{ncsimplebnf} |
322 | 315 | \terminal{\{}\br
|
323 |
| -\>init-statement\br |
324 |
| -\>\terminal{if \opt{constexpr} (} condition \terminal{)} statement \terminal{else} statement\br |
| 316 | +\bnfindent init-statement\br |
| 317 | +\bnfindent \terminal{if \opt{constexpr} (} condition \terminal{)} statement \terminal{else} statement\br |
325 | 318 | \terminal{\}}
|
326 |
| -\end{ncbnftab} |
327 |
| - |
| 319 | +\end{ncsimplebnf} |
328 | 320 | except that names declared in the \grammarterm{init-statement} are in
|
329 | 321 | the same declarative region as those declared in the
|
330 | 322 | \grammarterm{condition}.
|
|
400 | 392 |
|
401 | 393 | \pnum
|
402 | 394 | A \tcode{switch} statement of the form
|
403 |
| - |
404 |
| -\begin{ncbnf} |
| 395 | +\begin{ncsimplebnf} |
405 | 396 | \terminal{switch (} init-statement condition \terminal{)} statement
|
406 |
| -\end{ncbnf} |
407 |
| - |
| 397 | +\end{ncsimplebnf} |
408 | 398 | is equivalent to
|
409 |
| - |
410 |
| -\begin{ncbnftab} |
| 399 | +\begin{ncsimplebnf} |
411 | 400 | \terminal{\{}\br
|
412 |
| -\>init-statement\br |
413 |
| -\>\terminal{switch (} condition \terminal{)} statement\br |
| 401 | +\bnfindent init-statement\br |
| 402 | +\bnfindent \terminal{switch (} condition \terminal{)} statement\br |
414 | 403 | \terminal{\}}
|
415 |
| -\end{ncbnftab} |
416 |
| - |
| 404 | +\end{ncsimplebnf} |
417 | 405 | except that names declared in the \grammarterm{init-statement} are in
|
418 | 406 | the same declarative region as those declared in the
|
419 | 407 | \grammarterm{condition}.%
|
|
513 | 501 | \grammarterm{statement}. A \tcode{while} statement whose \grammarterm{condition}
|
514 | 502 | is an initialized declaration of some variable \tcode{t}
|
515 | 503 | is equivalent to
|
516 |
| - |
517 |
| -\begin{ncbnftab} |
| 504 | +\begin{ncsimplebnf} |
518 | 505 | \terminal{label:}\br
|
519 |
| -\terminal{\{}\>\>\>// start of condition scope\br |
520 |
| -\>condition \terminal{;}\>\>// declares \terminal{t}\br |
521 |
| -\>\terminal{if (t) \{}\br |
522 |
| -\>\>statement\br |
523 |
| -\>\>\terminal{goto label;}\br |
524 |
| -\>\terminal{\}}\br |
525 |
| -\terminal{\}}\>\>\>// end of condition scope |
526 |
| -\end{ncbnftab} |
527 |
| - |
| 506 | +\makebox[0pt][l]{\terminal{\{}}\bnfindent\bnfindent\bnfindent\bnfindent// start of condition scope\br |
| 507 | +\bnfindent\makebox[0pt][l]{condition \terminal{;}}\bnfindent\bnfindent\bnfindent// declares \terminal{t}\br |
| 508 | +\bnfindent \terminal{if (t) \{}\br |
| 509 | +\bnfindent\bnfindent statement\br |
| 510 | +\bnfindent\bnfindent \terminal{goto label;}\br |
| 511 | +\bnfindent \terminal{\}}\br |
| 512 | +\makebox[0pt][l]{\terminal{\}}}\bnfindent\bnfindent\bnfindent\bnfindent// end of condition scope |
| 513 | +\end{ncsimplebnf} |
528 | 514 | \begin{note}
|
529 | 515 | The variable created in the condition is destroyed and created with each
|
530 | 516 | iteration of the loop.
|
531 | 517 | \begin{example}
|
532 |
| - |
533 | 518 | \begin{codeblock}
|
534 | 519 | struct A {
|
535 | 520 | int val;
|
|
543 | 528 | i = 0;
|
544 | 529 | }
|
545 | 530 | \end{codeblock}
|
546 |
| - |
547 | 531 | In the while-loop, the constructor and destructor are each called twice,
|
548 | 532 | once for the condition that succeeds and once for the condition that
|
549 | 533 | fails.
|
|
567 | 551 |
|
568 | 552 | \pnum
|
569 | 553 | The \tcode{for} statement
|
570 |
| - |
571 |
| -\begin{ncbnf} |
| 554 | +\begin{ncsimplebnf} |
572 | 555 | \terminal{for (} init-statement \opt{condition} \terminal{;} \opt{expression} \terminal{)} statement
|
573 |
| -\end{ncbnf} |
574 |
| - |
| 556 | +\end{ncsimplebnf} |
575 | 557 | is equivalent to
|
576 |
| - |
577 |
| -\begin{ncbnftab} |
| 558 | +\begin{ncsimplebnf} |
578 | 559 | \terminal{\{}\br
|
579 |
| -\>init-statement\br |
580 |
| -\>\terminal{while (} condition \terminal{) \{}\br |
581 |
| -\>\>statement\br |
582 |
| -\>\>expression \terminal{;}\br |
583 |
| -\>\terminal{\}}\br |
| 560 | +\bnfindent init-statement\br |
| 561 | +\bnfindent \terminal{while (} condition \terminal{) \{}\br |
| 562 | +\bnfindent\bnfindent statement\br |
| 563 | +\bnfindent\bnfindent expression \terminal{;}\br |
| 564 | +\bnfindent \terminal{\}}\br |
584 | 565 | \terminal{\}}
|
585 |
| -\end{ncbnftab} |
586 |
| - |
| 566 | +\end{ncsimplebnf} |
587 | 567 | except that names declared in the \grammarterm{init-statement} are in
|
588 | 568 | the same declarative region as those declared in the
|
589 | 569 | \grammarterm{condition}, and except that a
|
|
629 | 609 |
|
630 | 610 | \pnum
|
631 | 611 | The range-based \tcode{for} statement
|
632 |
| - |
633 |
| -\begin{ncbnf} |
| 612 | +\begin{ncsimplebnf} |
634 | 613 | \terminal{for (} \opt{init-statement} for-range-declaration \terminal{:} for-range-initializer \terminal{)} statement
|
635 |
| -\end{ncbnf} |
636 |
| - |
| 614 | +\end{ncsimplebnf} |
637 | 615 | is equivalent to
|
638 |
| - |
639 |
| -\begin{ncbnftab} |
| 616 | +\begin{ncsimplebnf} |
640 | 617 | \terminal{\{}\br
|
641 |
| -\>\opt{init-statement}\br |
642 |
| -\>\terminal{auto \&\&__range =} for-range-initializer \terminal{;}\br |
643 |
| -\>\terminal{auto __begin =} begin-expr \terminal{;}\br |
644 |
| -\>\terminal{auto __end =} end-expr \terminal{;}\br |
645 |
| -\>\terminal{for ( ; __begin != __end; ++__begin ) \{}\br |
646 |
| -\>\>for-range-declaration \terminal{= *__begin;}\br |
647 |
| -\>\>statement\br |
648 |
| -\>\terminal{\}}\br |
| 618 | +\bnfindent \opt{init-statement}\br |
| 619 | +\bnfindent \terminal{auto \&\&__range =} for-range-initializer \terminal{;}\br |
| 620 | +\bnfindent \terminal{auto __begin =} begin-expr \terminal{;}\br |
| 621 | +\bnfindent \terminal{auto __end =} end-expr \terminal{;}\br |
| 622 | +\bnfindent \terminal{for ( ; __begin != __end; ++__begin ) \{}\br |
| 623 | +\bnfindent\bnfindent for-range-declaration \terminal{= *__begin;}\br |
| 624 | +\bnfindent\bnfindent statement\br |
| 625 | +\bnfindent \terminal{\}}\br |
649 | 626 | \terminal{\}}
|
650 |
| -\end{ncbnftab} |
651 |
| - |
| 627 | +\end{ncsimplebnf} |
652 | 628 | where
|
653 |
| - |
654 | 629 | \begin{itemize}
|
655 | 630 | \item
|
656 | 631 | if the \grammarterm{for-range-initializer} is an \grammarterm{expression},
|
|
0 commit comments