I wrote the following definitions in my latex document.
It seems that they work.
Just insert the above lines anywhere after your inclusion statement of the algorithmic package. Especially, to make the algorithm presentation concise, I distinguish between compound cases and one-line cases. The one-line cases begin with CASELINE. The compound cases begin with CASE and end with ENDCASE. Similar to the default statements.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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.
%%
ewcommand{SWITCH}[1]{STATE extbf{switch} (#1)}
ewcommand{ENDSWITCH}{STATE extbf{end switch}}
ewcommand{CASE}[1]{STATE extbf{case} #1 extbf{:} egin{ALC@g}}
ewcommand{ENDCASE}{end{ALC@g}}
ewcommand{CASELINE}[1]{STATE extbf{case} #1 extbf{:} }
ewcommand{DEFAULT}{STATE extbf{default:} egin{ALC@g}}
ewcommand{ENDDEFAULT}{end{ALC@g}}
ewcommand{DEFAULTLINE}[1]{STATE extbf{default:} }
%%
%% End of the LaTeX algorithmic package extension.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
你可以尝试以下例子。
SWITCH {$ heta$}
CASE {1}
STATE Hello
ENDCASE
CASELINE {2}
STATE Good-bye
DEFAULT
STATE Again ?
ENDDEFAULT
ENDSWITCH
Farn Wang
Dept. of Electrical Eng.
National Taiwan University