How can I write the else if block with condition with the usepackage algorithm2e
?
I want to write the following with the algorithm2e
package:
if(condition){
//code
}else if(condition){
// code
}else{
//code
}
Code:
\documentclass{article}
\usepackage{german,t1enc}
\usepackage{lipsum}
%Header part
\usepackage{fancyhdr}
\pagestyle{fancy}
%\cfoot{center of the footer!}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
%pseudocode.
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage[dvipsnames]{xcolor}
\renewcommand{\baselinestretch}{1.5}
%blacksquare
\usepackage{ amssymb }
\begin{document}
\begin{algorithm}[H]
function search(v,w,s) \\
binarsearch(v,w,s,0, |w|) \\
binarsearch(v,w,s,l, r) \\
\If{$v$ prefix of $w_s[m]$}{
return true;
}\ElseIf(elseif comment){
binarsearch(v,w,s,l,m-1)
}
\caption{}
\label{alg: initializer}
\end{algorithm}
Best Answer
To combine such conditions, write each as a separate component using
\uIf
and\uElseIf
(and\uElse
, if needed):