I would like to change my algorithm from while
loop to if condition. Every thing will be the same except the while
statement. On while
loop, change it to r < R
. I have tried many ways, but my script missed up.
Here is my original script for the while
\documentclass[conference]{IEEEtran}
\usepackage{algorithm}
\usepackage[algo2e]{algorithm2e}
\usepackage[]{algpseudocode}
\begin{algorithm}
\caption{Pseudo-code of Mine}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{Info}
\Output{SCORE}
\While{$r < R$}{
\State
\begin{varwidth}[t]{\linewidth} \par
$n\gets function(DataX, Datax1, DataX2,$ \par
\hskip\algorithmicindent $Type, Type2)$
\end{varwidth}
\State $S\gets function (S)$
\EndWhile}
\State $SCORE \gets Trained ANN(InfoInput)$
\end{algorithm}
My trying code is also to add else condition:
\begin{algorithm}
\caption{Pseudo-code of Mine}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{Info}
\Output{SCORE}
\if{$r < R$}{
\State
\begin{varwidth}[t]{\linewidth} \par
$n\gets function(DataX, Datax1, DataX2,$ \par
\hskip\algorithmicindent $Type, Type2)$
\end{varwidth}
\State $S\gets function (S)$
\Endif}
\State $SCORE \gets Trained ANN(InfoInput)$
\Else
{
\State
\begin{varwidth}[t]{\linewidth} \par
$n\gets function(DataX, Datax1, DataX2,$ \par
\hskip\algorithmicindent $Type, Type2)$
\end{varwidth}
\State $S\gets function (S)$
\Endif}
\State $SCORE \gets Trained ANN(InfoInput)$
\end{algorithm}
Best Answer
You are using the syntax of two different algorithm packages incorrectly. It seems like you're favouring
algorithm2e
for the general structure, while using analgorithmicx
-type syntax for some of the other components.Below I've used the traditional
algorithm2e
syntax to provide you with the layout you're after:Specifically note:
Use a
\;
to terminate the end of an input line within thealgorithm
environment. It - the semi-colon - will be printed by default, unless you issue\DontPrintSemicolon
.An if-statement has the syntax
\If{<cond>}{<then>}
, while an if-else-statement uses\eIf{<cond>}{<then>}{<else>}
.There is no
\State
withalgorithm2e
.