File:  [LON-CAPA] / loncom / html / adm / help / tex / Spreadsheet_Ternary_Operator.tex
Revision 1.2: download - view: text, annotated - select for diffs
Fri Jul 26 19:53:59 2002 UTC (21 years, 11 months ago) by bowersj2
Branches: MAIN
CVS tags: HEAD
.tex files from help.loncapa.org largely done. Added some lables to
older files. Last mega-massive .tex commit for a while.

\label{Spreadsheet_Ternary_Operator}
The ?'s and :'s seen in the spreadsheet cells are part of compact notation for an if-then-else clause. Something like:

\texttt{( B2 > 16 ? 'passing grade' : 'failing grade')}

can be translated into:

\texttt{if (B2 > 16 ) \{ \\
  \hspace*{16pt}     \$temp = 'passing grade';\\
  \} else \{ \\
  \hspace*{16pt}     \$temp = 'failing grade'; \\
  \} \\
  \$temp;\\
}

The nicest part of the \texttt{( ? : )} operator (aside from its
compactness) is the way it automatically returns the value you want
without having to use any temporary variables.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>