[Tex/LaTex] How to reinitialize the lines counter for algorithms

algorithm2ealgorithmicxalgorithmsline-numbering

I have four algorithms in a section but the problem is that the lines numbering doesn't start with 1 in each algorithm. For example, the first one is numbered from 1 to 11 but the second one start with line number 12 rather than 1. I want to know how can I reinitialize the lines counter for each algorithm to have lines numbers starting with 1?

Here is my code:

\documentclass[letterpaper,12pt,oneside,final]{book}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[ruled,algo2e,french]{algorithm2e}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{pdfpages}
\usepackage{epstopdf} 
\usepackage{amsmath,color,soulutf8,longtable,colortbl,setspace,ifthen,xspace,url,pdflscape} 
\makeatletter
\usepackage[frenchb]{babel}
\usepackage{caption}  
\begin{document}
\begin{algorithm}[H]
    \SetKwInput{Initialization}{Initialisation}
        \LinesNumbered
        \Initialization{}   
    \For{}{}
\end{algorithm}
\begin{algorithm}[h]
    \SetKwInput{Initialization}{Initialisation}
    \LinesNumbered
    \Initialization{}
    \For{}{}
\end{algorithm}
\end{document}

Best Answer

Use this simple code: \setcounter{AlgoLine}{<number>}. The Alg@line is incorrect. You should use Algoline

\begin{algorithm}[H]
    \SetKwInput{Initialization}{Initialisation}
        \LinesNumbered
        \Initialization{}   
    \For{}{}
\end{algorithm}
\begin{algorithm}[h]
    \setcounter{AlgoLine}{0}
    \SetKwInput{Initialization}{Initialisation}
    \LinesNumbered
    \Initialization{}
    \For{}{}
\end{algorithm}
Related Question