How can I add comments in the following algorithm based on package algorithmic
?
\documentclass[10pt,conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage{changepage}
\usepackage{lipsum}
\usepackage{ctable}% http://ctan.org/pkg/ctable
\usepackage{color, colortbl}
\newcommand*\ita[1]{\textit{#1}}
\usepackage{xcolor} % changed
\usepackage{array, booktabs, makecell, multirow}% new
\definecolor{Gray}{gray}{0.9}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{xcolor} % changed
\usepackage{array, booktabs, makecell, multirow}% new
\usepackage{multirow}
\newcommand{\var}{\textit}
\newcommand{\proc}{\textbf}
\newcommand{\prop}{\texttt}
\newcommand{\plusplus}{{+}{+}}% Other options:
\begin{document}
\begin{algorithm}
\caption{Step 2-N Propagation}
\begin{algorithmic}[1]
\raggedright
\STATE boolean modified=true
\WHILE{modified==true}
\STATE modified=false
\FORALL{r in Requirements}
\FORALL{m in Methods}
\IF {m.trace[r]==E \AND
(m.interfaces.trace[r].AllNs() \OR
m.implementations.trace[r].AllNs() \OR m.parents.trace[r].AllNs() \OR
m.children.trace[r].AllNs())
}
%\STATE\proc{//Inheritance}
\STATE m.trace[r]=N
\STATE modified=true
\ENDIF
\ENDFOR
\ENDFOR
\FORALL{r in Requirements}
\FORALL{m in Methods}
\IF {m.trace[r]==E \AND
%!m.XCallers.isEmpty()
%\AND
m.XCallers.trace[r].AllNs())
}
% \STATE\proc{//All XCallers N}
\STATE m.Trace[r]=N
\STATE modified=true
\ENDIF
\ENDFOR
\ENDFOR
\FORALL{r in Requirements}
\FORALL{m in Methods}
\IF {m.trace[r]==E \AND
%!m.XCallees.isEmpty()
%\AND
m.XCallees.trace[r].AllNs())
}
% \STATE\proc{//All XCallees N}
\STATE m.trace[r]=N
\STATE modified=true
\ENDIF
\ENDFOR
\ENDFOR
\ENDWHILE
\end{algorithmic}
\label{step2}
\end{algorithm}
\end{document}
I would like my algoritm to look like I would like to insert //Inheritance
next to the \if
statement. I would like to have my algorithm look like this:
Best Answer
Well, with your used packages you can use the command
\COMMENT
to add an comment to a line, if you want the comment to end on the right side use\hfill\COMMENT
.See an example here (please note that I minimalized your given algorithm and I reduced the called packages to that one needed for this issue):
and its result:
Based on your shown image you can use package
algorithmicx
andalgpseudocode
to get something simular to your shown image.See the new code
and its result:
Please see the inserted comment with commands
\hfill\Comment
(red arrow, marked with 1) and see the different indention (red arrow 2). Please see that you have to rewrite the algorithmn completly for the second code! Please read the corresponding documentation withtexdoc algorithmicx
on your terminal ...