Skip to content

Commit f052b32

Browse files
zygoloidtkoeppe
authored andcommitted
[stmt.ranged] Repeat grammar snippet to clarify what we mean by a
"range-based for statement", and improve formatting to match that of [stmt.for]. Also add some missing italics for grammar terms in [stmt.for].
1 parent 1d77bb3 commit f052b32

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

source/statements.tex

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,11 @@
475475

476476
except that names declared in the \grammarterm{for-init-statement} are in
477477
the same declarative region as those declared in the
478-
\grammarterm{}{condition}, and except that a
478+
\grammarterm{condition}, and except that a
479479
\indextext{statement!\tcode{continue}~in \tcode{for}}%
480-
\tcode{continue} in \grammarterm{}{statement} (not enclosed in another
481-
iteration statement) will execute \grammarterm{}{expression} before
482-
re-evaluating \grammarterm{}{condition}.
480+
\tcode{continue} in \grammarterm{statement} (not enclosed in another
481+
iteration statement) will execute \grammarterm{expression} before
482+
re-evaluating \grammarterm{condition}.
483483
\enternote
484484
Thus the first statement specifies initialization for the loop; the
485485
condition~(\ref{stmt.select}) specifies a test, sequenced before each
@@ -489,8 +489,10 @@
489489
\exitnote
490490

491491
\pnum
492-
Either or both of the condition and the expression can be omitted. A
493-
missing \grammarterm{}{condition} makes the implied \tcode{while} clause
492+
Either or both of the \grammarterm{condition}
493+
and the \grammarterm{expression} can be omitted.
494+
A missing \grammarterm{condition}
495+
makes the implied \tcode{while} clause
494496
equivalent to \tcode{while(true)}.
495497

496498
\pnum
@@ -515,20 +517,26 @@
515517
\indextext{statement!range~based \idxcode{for}}
516518

517519
\pnum
518-
A range-based \tcode{for} statement is equivalent to
520+
The range-based \tcode{for} statement
519521

520-
\begin{codeblock}
521-
{
522-
auto && __range = @\grammarterm{for-range-initializer}@;
523-
for ( auto __begin = begin-expr,
524-
__end = end-expr;
525-
__begin != __end;
526-
++__begin ) {
527-
@\grammarterm{for-range-declaration}@ = *__begin;
528-
@\grammarterm{statement}@
529-
}
530-
}
531-
\end{codeblock}
522+
\begin{ncbnf}
523+
\terminal{for (} for-range-declaration \terminal{:} for-range-initializer \terminal{)} statement
524+
\end{ncbnf}
525+
526+
is equivalent to
527+
528+
\begin{ncbnftab}
529+
\terminal{\{}\br
530+
\>\terminal{auto \&\&__range =} for-range-initializer \terminal{;}\br
531+
\>\terminal{for ( auto __begin =} begin-expr \terminal{,}\br
532+
\>\terminal{ \ \ \ \ \ \ \ \ \ \ __end =} end-expr \terminal{;}\br
533+
\>\terminal{ \ \ \ \ \ __begin != __end;}\br
534+
\>\terminal{ \ \ \ \ \ ++__begin ) \{}\br
535+
\>\>for-range-declaration \terminal{= *__begin;}\br
536+
\>\>statement\br
537+
\>\terminal{\}}\br
538+
\terminal{\}}
539+
\end{ncbnftab}
532540

533541
where
534542

0 commit comments

Comments
 (0)