# How to solve ! Undefined control sequence. error in Latex

I am using packages \usepackage{algpseudocode}, \usepackage{algorithm} to run below algorithm but it gace error!

Undefined control sequence. l.1248 \IF $f(X_{i})$ better $f(X_{k})$?

Please tell me what is the problem?

\begin{algorithm}%[h]

\caption{GTLBO}

\begin{algorithmic}

\State initialize no of students, no of subjects i.e., variables, termination criteria

\State Calculate the mean of each variable or subjects

\State Find the best solution and best variable value

\While Stopping condition not met

\For {for each learner X, of the class} %Teaching phase}

\State $TeachingPhase=round(1+rand(0, I))$

\For j=1:D

\State $newX_{ij} = X_{ij} + rand(0, 1) \ast (Teacher(j)-TeachingPhase \ast Mean(j)$

\EndFor

\State Accept $newX_{i} if f(newX_{i}) is better than f(X_{i})$

\EndFor

\For each learner $X_{i}$ of the class % Learning phase

\State  Randomly select one learner $X_{k}$, such that $i \neq k$

\IF $f(X_{i})$ better $f(X_{k})$

\For $j= 1:D$

\State    $newX_{ij} =X_{ij}+rand(0, 1) \ast (X_{ij}-X_{kj})$

\EndFor

\Else

\For $j= 1:D$

\State    $newX_{ij}$ = $X_{ij}$+rand(0, 1) $\ast$ $(X_{kj}-X_{ij})$

\Endfor

\EndIF

\State Accept $newX_{i}$ if $f(newX_{i})$ is better than $f(X_{i})$

\EndFor

\State Update the Teacher and the Mean

\EndWhile

\End

\end{algorithmic}

\end{algorithm}

• You have to write \If instead of \IF. – Marcel Krüger Mar 26 '18 at 8:03