Using the Latex Algorithmic Package for a Switch Statement?

My googling did not come up with how to make a switch statement in an algorithm using an algorithm and algorithmic packages, but I guess you can. Most guides just didn't mention it anyway.

\begin{algorithm}
\caption{send(...) method}
\begin{algorithmic}
\IF{dest equals..}
%\SWITCH{nature}
\STATE cast data...
\STATE extract data...
\STATE copy...
%\ENDSWITCH
\ELSE
\STATE match dest....
%\SWITCH{nature}
\STATE cast data...
\STATE extract data...
\STATE send...
%\ENDSWITCH
\ENDIF
\end{algorithmic}
\end{algorithm}

Thank!

+5
source share
2 answers

. , . . , , . \CASELINE. \CASE \ENDCASE. .

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The following definitions are to extend the LaTeX algorithmic 
%% package with SWITCH statements and one-line structures.
%% The extension is by 
%%   Prof. Farn Wang 
%%   Dept. of Electrical Engineering, 
%%   National Taiwan University. 
%% 
\newcommand{\SWITCH}[1]{\STATE \textbf{switch} (#1)}
\newcommand{\ENDSWITCH}{\STATE \textbf{end switch}}
\newcommand{\CASE}[1]{\STATE \textbf{case} #1\textbf{:} \begin{ALC@g}}
\newcommand{\ENDCASE}{\end{ALC@g}}
\newcommand{\CASELINE}[1]{\STATE \textbf{case} #1\textbf{:} }
\newcommand{\DEFAULT}{\STATE \textbf{default:} \begin{ALC@g}}
\newcommand{\ENDDEFAULT}{\end{ALC@g}}
\newcommand{\DEFAULTLINE}[1]{\STATE \textbf{default:} }
%% 
%% End of the LaTeX algorithmic package extension.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

.

\SWITCH {$\theta$}
\CASE {1}
  \STATE Hello
\ENDCASE
\CASELINE {2}
  \STATE Good-bye
\DEFAULT
  \STATE Again ?
\ENDDEFAULT
\ENDSWITCH

.

+3

CTAN , , SWITCH-CASE -. , , ​​ ;)

+2

All Articles