I want to use the IF else in my code using LaTeX. But I am unable to end the if-else. I have used the ENDIF and the commands like this \newcommand\sIf[2]{ \If{#1}#2\EndIf}
. I want to print the END if at the end of the if-else. The following is the code and its output.
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Calculating Speed Using GPS}\label{alg1}
\begin{algorithmic}[1]
\State $distance\gets 0 $
\State $time\gets 0 $
\State $speedGPS \gets 0 $
\If{$location.hasSpeed()$}
\State $speedGPS\gets location.getSpeed()$
\Else
\State $speedGPS \gets dist / time$
\EndIf
\State $counter \gets (counter + 1) \% data_points$
\State $speedGPS \gets speedGPS * 3.6d$
\end{algorithmic}
\end{algorithm}
\end{document}