\usepackage[ruled,linesnumbered]{algorithm2e}
\begin{algorithm}
\caption{pseudocode}\label{pseudocode}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
\Input{input data}
\Output{output, if return none, this line can be ignored}
a=1\;
\Repeat{Stop condition satisfied}{
\For{$x_{batch}^s \in X_s,x_{batch}^t \in X_t$}{
\eIf{understand}{
a = 2\;
a = 3\;
}{
a = 4\;
}
\If{a=1}{
a = 0\;
}
\uIf{condition1}{
something if \;
}
\uElseIf{condition2}{
something elseif \;
}
\uElseIf{condition3}{
something elseif \;
}
\Else{
something else \;
}
}
}
\end{algorithm}

常用的循环,条件都包括了。
如果想让一些斜体不斜,可以用\textnormal{}
伪代码与循环条件控制
这篇博客展示了如何使用算法2e宏包编写伪代码,包括常见的循环和条件判断结构,如 Repeat-Until、For循环、If-ElseIf-Else条件判断,以及嵌套的条件处理。适合理解算法流程和编程逻辑。
3714

被折叠的 条评论
为什么被折叠?



