4

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?

3
  • 2
    Welcome to TeXSE. Please tell us which document class and which algorithm-related packages you employ.
    – Mico
    Dec 19, 2021 at 20:38
  • 4
    Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Dec 19, 2021 at 20:38
  • 1
    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

1 Answer 1

7

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.

enter image description here

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

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .