[Tex/LaTex] Help with algorithm2e formatting

algorithm2ealgorithmsformatting

recentely I've got into a bit more advanced LaTeX formatting, i.e algorithms. My package of choice is the algorithm2e package, but I'm having some difficulities operating it.

So I've wanted to create an algorithm using the algorithm2e package, but I can't quite wrap my head around how it operates.

Here is my code.

As for packages, all I've used is

\usepackage{amsmath}
\usepackage[linesnumbered]{algorithm2e}

amsmath for mathematical library
and re-set the algorithm2e to enumerate the lines of my algorithm

\SetAlgoNoLine
\begin{algorithm}[H] 
    \DontPrintSemicolon
    \KwIn{$X_{t-1}, u_t. z_t$}
    \KwOut{$X_t$}
    $\overline{X_t} = X_t = 0$\;
    \For{$k = 1$ to $M$}{
        $x^{[k]}_t = sample\_motion\_model(u_t, x^{[k]}_{t-1})$\;
        $w^{[k]}_t = measurement\_model(z_t, x^{[k]}_t, m_{t-1})$\;
        $m^{[k]}_t = updated\_occupancy\_grid(z_t, x^{[k]}_t, m^{[k]}_{t-1})$\;
        $\overline{X_t} = \overline{X_t} + \langle x_x^{[m]}, w_t^{[m]} \rangle $\;
        }
    \For {$k = 1$ to $M$}{
        draw i with probability $\approx w_t^{[i]}$\;
        add $\langle x_x^{[m]}, w_t^{[m]} \rangle$ to $X_t$\;
        }
    \Return $X_t$
    \caption{FastSLAM}
\end{algorithm}

Which produces this:

fielded result

My desired result would be:

desired

So I've got 5 questions.

1) How can I redefine the algorithm2e to print "Algoritmus" instead of Algorithm in place of my caption? *Answered in comments
2) Probably will have similar solution as 1), but is it possible for my algorithm to print end for instead of only end?
3) How to place the caption title on the top instead of the bottom of the algorhitm?
4) How to add the <hr>look-a-like line break in the specific parts of algorithm?
5) Is it good practice inside the \For loop to define it as \For{$k = 1$ to $M$}{ code.. }? Seems a bit artificial to me to add the word to there. Isn't there an inbuilt function for this?

EDIT: Found a solution to question number 3 and 4. Studied the algorithm2e.sty file and found solution.

For those wondering, change the package definition to \usepackage[linesnumbered, ruled, vlined]

Produces the following:

edited

The remaining questions however still stand.

Best Answer

Supposing your document is in German , loading babel with german set via document class does the trick. To replace end with endfor, overwrite the definition of For with \SetKwFor:

\documentclass[german] {article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel} \usepackage[linesnumbered, ruled, vlined]{algorithm2e}

\SetKwFor{For}{for}{do}{endfor for}%

\begin{document}

\SetAlgoNoLine
\begin{algorithm}[H]
  \DontPrintSemicolon
  \KwIn{$X_{t-1}, u_t ยท z_t$}
  \KwOut{$X_t$}
  $\overline{X_t} = X_t = 0$\;
  \For{$k = 1$ to $M$}{
    $x^{[k]}_t = sample\_motion\_model(u_t, x^{[k]}_{t-1})$\;
    $w^{[k]}_t = measurement\_model(z_t, x^{[k]}_t, m_{t-1})$\;
    $m^{[k]}_t = updated\_occupancy\_grid(z_t, x^{[k]}_t, m^{[k]}_{t-1})$\;
    $\overline{X_t} = \overline{X_t} + \langle x_x^{[m]}, w_t^{[m]} \rangle $\;
  }
  \For {$k = 1$ to $M$}{
    draw $ i $ with probability $\approx w_t^{[i]}$\;
    add $\langle x_x^{[m]}, w_t^{[m]} \rangle$ to $X_t$\;
  }
  \Return $X_t$
  \caption{FastSLAM}
\end{algorithm}

\end{document} 

enter image description here