Y-asc

yet another stupid compiler
Log | Files | Refs | README | git clone https://git.ne02ptzero.me/git/Y-asc

commit e0480fac24ef303ca4cfb7a978a0781580c113d6
parent be7712c3961688e4e8823c0ee960aaa62bc86286
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Thu, 29 Jun 2017 18:22:58 +0200

Add(Tex): Finish section on if-else

Diffstat:
Mtex/yasc.tex | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/tex/yasc.tex b/tex/yasc.tex @@ -480,6 +480,28 @@ Operators & Associativity\\ \begin{lstlisting} if (expression != 0) \end{lstlisting} + Because the \texttt{else} part on an \texttt{if-else} is optionnal, + there is ambiguity when an else if ommited from a nested \texttt{if} + sequence. This is resolved by associating the \texttt{else} with + the closest previous \texttt{else}-less \texttt{if}. For example, in + \begin{lstlisting} + if (n > 0) + if (a > b) + z = a; + else + z = b; + \end{lstlisting} + the \texttt{else} goes to the inner \texttt{if}, as we have shown by + indentation. If that isn't the desired behaviore, one must use braces + to force the proper association: + \begin{lstlisting} + if (n > 0) { + if (a > b) + z = a; + } + else + z = b; + \end{lstlisting} \subsection{Else-If} \subsection{Loops - While}