# Goto command in algorithm2e package

I use the following code

N(a,n,i,j,y){

$p \gets 1$\;
$z \gets 1$\;
\While {$z \leq n$}{
\eIf{$a[y][z] = 0$}
{
$z \gets z+1$\;

}{
\eIf{$a[i][j] = a[y][z]$}
{
%$c \gets 0$\;
$p \gets 0$\;
$z \gets z+1$\;
\KwGoTo \ref{37}\;
}{
%$c \gets 1$\;
$p \gets 1$\;
$z \gets z+1$\;
}
}
}
}

\eIf{$p=1$} //line# 37
{
Print "Yes, The color assigned to $u_i$ $u_j$ follows strong edge coloring"
}{
Print "The color assigned to $u_i$ $u_j$ matches with the color of $u_y$ $u_z$" \newline
Print "No, the color assigned to $u_i$ $u_j$ doesn't follow strong edge coloring"

}


I'm trying to use the algorithm2e package to write down an algorithm. This uses a subroutine N(a,n,i,j,y). When the variable p takes up a zero value, which is possible when line#28 is executed, i want the control to exit the subroutine N(a,n,i,j,y) and then execute the conditional statements in lines 37,38 and 39.

I followed the suggestion by Marco Daniel and used this command \KwGoTo \ref{outer_loop};

as described in this post How to typeset gotos and labels using LaTeX pseudocode environments?

The output shows a pair of question marks next to the goto keyword as shown in the attached image.

I'd be thankful to anyone who can spot what I'm missing in the code and help me rectify it.

• Welcome to TwX.SE. You should show in question, what you do so far (in form of small compilable document) and where you stuck. Commented May 29, 2022 at 9:39
• A screenshot is fine, but not suffcient. What we need is Latex code, which we can copy&run. Please provide it, using the Edit button. Thanks Commented May 29, 2022 at 10:06
• Thanks MS-SPO, I've included the code now. Commented May 29, 2022 at 10:43
• In \ref{37}, the number 37 is not what is printed, but the label of the line that you want to reference. So add \label{37} in the line that you are referring to (better use a string instead of 37, that conveys the meaning of the code at line 37). Compare your code to the code that you are linking to. There, \label{marker} and \ref{marker} is used. Commented May 29, 2022 at 11:25
• Thanks @gernot. That worked. Commented Jun 7, 2022 at 8:51