Algorithm – More \State on same line

algorithmicalgorithms

I have this algorithm:

\begin{algorithm}
  \begin{algorithmic}[1]
    \caption{Build-PGM-Index}
    \State{levels} = array dinamico vuoto;
    \State{i} = 0;
    \State{keys} = A;
    \Repeat
      \State{$M$} = Build-PLA-model($keys, \epsilon$);
      \State{levels[i]} = $M$; \State{i} = $i + 1$;
      \State{m} = $Size(M)$;
      \State{keys} = $[M[0].key, \dots, M[m-1].key]$
    \Until{m = 1}\\
    \Return{levels rovesciato}
  \end{algorithmic}
\end{algorithm}

How can I write the \State{i} = 0; and \State{keys} = A; on the same line?

Best Answer

\State does not receive an argument; just use

\State i=0; keys = A

However, your typesetting is inconsistent. Use math when needed.

\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm,algpseudocode}

\begin{document}

\begin{algorithm}
  \begin{algorithmic}[1]
    \caption{Build-PGM-Index}
    \State $\mathit{levels} = \text{array dinamico vuoto}$;
    \State $i = 0$; $\mathit{keys} = A$;
    \Repeat
      \State $M = \textup{Build-PLA-model}(\mathit{keys}, \epsilon)$;
      \State $\mathit{levels}[i] = M$; $i = i + 1$;
      \State $m = \textup{Size}(M)$;
      \State $\mathit{keys} = [M[0].\mathit{key}, \dots, M[m-1].\mathit{key}]$
    \Until{$m = 1$}\\
    \Return $\mathit{levels}$ rovesciato
  \end{algorithmic}
\end{algorithm}

\end{document}

enter image description here