2

I have the following code:

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}

\begin{algorithm}
\caption{Main Ass}\label{alg:cap}
\begin{algorithmic}[1]
\State Create
\State Create 
\State Create 
\For{every $T_i$}
\If{$T_i$ is an }
    \If {$T_i$ is of}
    \If {$A \notin$}
    \State add A
    \EndIf
    \EndIf
\ElsIf {$T_i$ is a}
    \If {$T_i$ is}
    \If{A $\in$ DI\_L}
    \If{linked}
    \State Create a 
    \EndIf
    \State add t 
    \EndIf
\ElsIf{$T_i$ is a}
\If{$T_i$ is of $}
\If{A $\in$ }
\State add r
\State add A
\EndIf
\EndIf
\If{$T_i$}
\If{invalid}
\State add w
\ElsIf{$A$}
\State delete A
\EndIf
\EndIf
\If{$c_i$ is found } 
\State delete the
\ElsIf{$a_i$ is found}
\State delete
\EndIf
\EndIf
\Endfor //talking about this for loop not closing, that is line 47
\State Send F
\State Send 
\end{algorithmic} \\that is line 50
\end{algorithm}


\begin{algorithm}
\caption{Main Rec}\label{alg:cap2}
\begin{algorithmic}[1]
\For {each t} \\that is line 57
\State execute $T_i$

\end{algorithmic} \\that is line 60
\end{algorithm}

\end{document}

Obviously, I deleted most of the lines of code to make things clearer, even though I closed my for loop, the visual changes aren't reflecting and I am getting multiple errors in compilation the rest appears fine visually

I am getting the following (I commented the code to mark which line each error refers to):

Missing number, treated as zero.

‪main.tex, 47‬
<to be read again> 
                   \ALG@b@2@EndFor@0 
l.47 \EndFor
            
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
Package algorithmicx Error: Some blocks are not closed!!!.

 
‪main.tex, 50‬
See the algorithmicx package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.50 \end{algorithmic}
                      
This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.
Missing \endcsname inserted.

 
‪main.tex, 57‬
<to be read again> 
                   \ALG@currentblock@0 
l.57 \For
          {each transaction in the linked list}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

! Extra \endcsname.
\ALG@makebeginrepeat ...\ALG@thisblock \endcsname 
                                                  \relax \def \ALG@thisblock...
l.57 \For
          {each transaction in the linked list}
I'm ignoring this, since I wasn't doing a \csname.
Package algorithmicx Error: Some blocks are not closed!!!.

 
‪main.tex, 60‬
See the algorithmicx package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.60 \end{algorithmic}
                      
(That was another \errmessage.)

Any help would be appreciated, I already tried making sure every opened block is closed and it looks like it, I am suspecting it might me some confusing with using the packages but I can't seem to figure it out

1 Answer 1

2

Count the number of \If commands and of the corresponding \EndIf. You'll see that they don't match.

If you properly indent the nested structures, you'll see.

I don't know where to precisely add the missing \EndIf. Here's a possibility, fix it.

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}

\begin{algorithm}
\caption{Main Ass}\label{alg:cap}
\begin{algorithmic}[1]
\State Create
\State Create 
\State Create 
\For{every $T_i$}
  \If{$T_i$ is an }
    \If {$T_i$ is of}
      \If {$A \notin$}
        \State add A
      \EndIf
    \EndIf
  \ElsIf {$T_i$ is a}
    \If {$T_i$ is}
      \If{A $\in$ DI\_L}
        \If{linked}
          \State Create a 
        \EndIf
          \State add t 
      \EndIf
    \ElsIf{$T_i$ is a}
      \If{$T_i$ is of}
        \If{A $\in$ }
          \State add r
          \State add A
        \EndIf
      \EndIf
      \If{$T_i$}
        \If{invalid}
          \State add w
        \ElsIf{$A$}
          \State delete A
        \EndIf
      \EndIf
    \EndIf % <--- Here?
    \If{$c_i$ is found } 
      \State delete the
    \ElsIf{$a_i$ is found}
      \State delete
    \EndIf
  \EndIf
\EndFor
\State Send F
\State Send 
\end{algorithmic}
\end{algorithm}

\end{document}
2
  • while counting the if statements do we include or exclude the elsif
    – Sergio
    Oct 19, 2021 at 14:37
  • @Sergio No, we don't. An \If can have as many \ElsIf as you want.
    – egreg
    Oct 19, 2021 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.