# How to print in algorithmic package for some If condition or For loop in one line?

How to print

\FOR{$j:=0,\ldots,i-1$}
\STATE{$\C_{ij}:=\C_{ii}\cdot\C_{ij}$};
\ENDFOR


in one line instead of two line?

-
Welcome to TeX.sx! Please always add a full, but minimal working example (MWE) that illustrates your problem. –  Martin Scharrer Jul 11 '11 at 15:20

You should define your own command for placing algorithmic content on a single line. As a suggestion, consider:

\newcommand{\LINEFOR}[2]{%
\STATE\algorithmicfor\ {#1}\ \algorithmicdo\ {#2} \algorithmicend\ \algorithmicfor%
}


which prints the regular algorithmic package keywords used in the construction of a for statement (\algorithmicfor, \algorithmicdo, etc.), but does all of this in a single \STATE statement (or line).

Here is a complete minimal example illustrating the result:

\documentclass{article}
\usepackage{algorithmic}%
\begin{document}

\newcommand{\LINEFOR}[2]{%
\STATE\algorithmicfor\ {#1}\ \algorithmicdo\ {#2} \algorithmicend\ \algorithmicfor%
}

\begin{algorithmic}
\STATE \ldots
\FOR{$j:=0,\ldots,i-1$}%
\STATE $\mathcal{C}_{ij}:=\mathcal{C}_{ii}\cdot\mathcal{C}_{ij}$;%
\ENDFOR%
\STATE \ldots
\LINEFOR{$j:=0,\ldots,i-1$}{$\mathcal{C}_{ij}:=\mathcal{C}_{ii}\cdot\mathcal{C}_{ij}$}%
\STATE \ldots
\end{algorithmic}

\end{document}

-
Thank you very much –  Mohammad Jul 12 '11 at 14:47
A version that makes an if one one line: newcommand{\LineIf}[2]{ \State \algorithmicif\ {#1}\ \algorithmicthen\ {#2} \algorithmicend\ \algorithmicif } –  dtech Sep 18 '13 at 15:19