# Algorithm not formatting correctly

I'm trying to write an algorithm in latex, but after I put my if statement it gives me back an error and says that there's a missing number. What does that mean? Where is my flaw? This is what I've written (mind you I'm trying to write a generalized algorithm that doesn't necessarily examine things, hence the general statement in if):

\For{j = length($y_i$)}{
\If{$\{x_j$ and $\neg x_j\}$ in $y_i$}{
\State \text{$a_i$ = F}
}


Can I do that?

• Welcome to TeXSE. Please tell us which document class and which algorithm-related packages you employ.
– Mico
Dec 19, 2021 at 20:38
• Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Dec 19, 2021 at 20:38
• Welcome to TeXSE. Please provide code which can be compiled as is for reproducing the erroneous behavior/the error-messages. Otherwise things can't be tracked down. Dec 19, 2021 at 21:53

It seems you're mixing up the syntax of algpseudocode with that of algorithm2e.

With the former package, the syntax is like as follows

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

\begin{document}

\begin{algorithmic}[1]
\For{$j = \operatorname{length}(y_i)$}
\If{$\{x_j$ and $\neg x_j\}$ in $y_i$}
\State $a_i = \mathrm{F}$
\EndIf
\EndFor
\end{algorithmic}

\end{document}


The latter package has no \State command, so I guess you're using algpseudocode.

Note the changes I made to your input to use math mode wherever it's needed.

• Which package of both would you recommend to go with generally?
– Diaa
Dec 19, 2021 at 23:50