5

I get the following error when I compile:

Syntax error; Undefined control sequence \EndIf

Code:

\usepackage{algorithm2e} 

\begin{algorithm}[h]
\label{FecEncodeAndSendFECUnits}
\caption{Function for Receiving and FEC-decoding FEC-encoded Units of Data}
\KwIn{}
%\KwOut{codeRate}

         nrOfPacketsReceived = 0             HIGHEST\_FEC\_UNIT\_NR\_DECODED\_GLOBAL=0          \While{$true$}
            currentPacket = ListenToSocketForNewPkt ()              $ nrOfPacketsReceived++ $               $ currentFecUnit =ExtractValueOfPktHeader(currentPacket, FEC_UNIT_GLOBAL) $                 $ currentFecUnitModulo$ = $currentFecUnit$ \% NR\_OF\_PARALLELL\_FEC\_UNITS\_GLOBAL $               $ currentSymbolNr$ = ExtractValueOfPktHeader($currentPacket$, SYMBOL\_NR\_GLOBAL) $                   packetForCurrentFecUnitGlobal[$currentFecUnitModulo$][$currentSymbolNr$] = ExtractDataOfPkt ($currentPacket$)                 \If { $ currentFecUnit$ > $HIGHEST_FEC_UNIT_NR_DECODED_GLOBAL$ OR
            ( currentFecUnit == 0 AND   nrOfPacketsReceived == 1 ) }
              ExtractPktHeaderAndPutIntoGlobalFecUnitHeaderValues () 
            \EndIf

             \If {currentFecUnit > HIGHEST\_FEC\_UNIT\_NR\_DECODED\_GLOBAL }            
                lastFecUnitModulo  = (currentFecUnit -1 ) \% NR\_OF\_PARALLELL\_FEC\_UNITS\_GLOBAL                      DecodeFECUnit (lastFecUnitModulo, nrOfSrcSymbolsGlobal[lastFecUnitModulo], nrOfTotalSymbolsGlobal[lastFecUnitModulo], symbolSizeGlobal[lastFecUnitModulo], rateOfRedundantPkts[lastFecUnitModulo]) \\

                $ HIGHEST\_FEC\_UNIT\_NR\_DECODED\_GLOBAL++$ \  
             \EndIf

        \EndWhile               

\end{algorithm}

How do I solve this?

David Carlisle
  • 757,742
  • 4
    Hi Anders, welcome to TeX.sx! :) I'm confused, I took a look at the algorithm2e documentation and found no occurrences of both \EndIf and \EndWhile. It seems the correct syntax of both \While and \If is slightly different than the one you are using. – Paulo Cereda Aug 07 '12 at 01:09

2 Answers2

8

You are mixing packages algorithm2e (\KwIn) with package algorithmicx. The latter uses

\If{<body>}
  <then block>
\EndIf
% also with else branches
\While{<condition>}
  <body>
\EndWhile

whereas package algorithm2e provides

\If{<condition>}{<then block>}
\While{<condition>}{<body>}

and lots of other forms.

Decide, which package you want to use and read its documentation.

Heiko Oberdiek
  • 271,626
5

There's no \EndIf nor \EndWhile; you have to use parentheses to specify the scope:

\If{<condition>}{<instructions>}
\While{<condition>}{<instructions>}

So, in your case, you could use (I wasn't sure whether to insert or not line change commands \\ at some points):

\documentclass{article}
\usepackage{algorithm2e} 

\begin{document}

\begin{algorithm}[h]
\label{FecEncodeAndSendFECUnits}
\caption{Function for Receiving and FEC-decoding FEC-encoded Units of Data}
\KwIn{}
%\KwOut{codeRate}

         nrOfPacketsReceived = 0              HIGHEST\_FEC\_UNIT\_NR\_DECODED\_GLOBAL=0 \\
        \While{$true$}{
            currentPacket = ListenToSocketForNewPkt ()                 $ nrOfPacketsReceived++ $                 $ currentFecUnit =ExtractValueOfPktHeader(currentPacket, FEC_UNIT_GLOBAL) $                 $ currentFecUnitModulo$ = $currentFecUnit$ \% NR\_OF\_PARALLELL\_FEC\_UNITS\_GLOBAL $                 $ currentSymbolNr$ = ExtractValueOfPktHeader($currentPacket$, SYMBOL\_NR\_GLOBAL) $                   packetForCurrentFecUnitGlobal[$currentFecUnitModulo$][$currentSymbolNr$] = ExtractDataOfPkt ($currentPacket$) \\
            \If{ $ currentFecUnit$ > $HIGHEST_FEC_UNIT_NR_DECODED_GLOBAL$ OR
            ( currentFecUnit == 0 AND   nrOfPacketsReceived == 1 ) }{
              ExtractPktHeaderAndPutIntoGlobalFecUnitHeaderValues () 
            }

             \If {currentFecUnit > HIGHEST\_FEC\_UNIT\_NR\_DECODED\_GLOBAL }{            
                lastFecUnitModulo  = (currentFecUnit -1 ) \% NR\_OF\_PARALLELL\_FEC\_UNITS\_GLOBAL                      DecodeFECUnit (lastFecUnitModulo, nrOfSrcSymbolsGlobal[lastFecUnitModulo], nrOfTotalSymbolsGlobal[lastFecUnitModulo], symbolSizeGlobal[lastFecUnitModulo], rateOfRedundantPkts[lastFecUnitModulo]) \\

                $ HIGHEST\_FEC\_UNIT\_NR\_DECODED\_GLOBAL++$ \  
             }
        }               
\end{algorithm}

\end{document}

enter image description here

As a side note, the algorithmicx package could be of interest for you; it has great functionality and it is highly customizable.

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128