5

Here is a MWE:

\documentclass{article}

\begin{document}
\ExplSyntaxOn
\int_step_inline:nn { 5 }
  {
    #1
    \int_compare:nNnT {#1} > {3}
      {
        % I want to stop for this case
      }
  }
\ExplSyntaxOff
\end{document}

I want to stop the process of \int_step_inline or some similar functions on some particular condition. I know there is break of continue in Python. Is there any similar functions in LaTeX3 that do the same things?

1
  • I guess I'm wondering why you'd want to do this - the step function is for the case where you know you want to use every value in a range.
    – Joseph Wright
    Feb 16 at 7:32

1 Answer 1

5

Although it's not currently documented, one can use the generic \prg_break: to terminate these constructs early:

\ExplSyntaxOn
\int_step_inline:nn { 100 }
  {
    \int_compare:nNnT {#1} > { 50 }
      { \prg_break: }
    \message { #1 }
  }
\stop
5
  • I check it in interface3 and I saw \prg_break is used with \prg_break_point:, but what about the case here?
    – xdyy
    Feb 16 at 8:28
  • 1
    @xdyy \prg_break_point: provides a generic mechanism to implement mappings and similar with a 'way out' using \prg_break:. It's therefore used in the implementation of \int_step_inline:nn and similar functions. Like I said, that's not documented - I guess I will need to raise with the team.
    – Joseph Wright
    Feb 16 at 8:30
  • I wonder what's the functions of \message and \stop here?
    – xdyy
    Feb 16 at 8:37
  • 1
    @xdyy They are for the demo: \message gets TeX to write to the terminal and log, so we don't have to worry about typesetting anything to see the result. \stop is a LaTeX command that just stops the run - useful in demos or debugging.
    – Joseph Wright
    Feb 16 at 8:39
  • Thanks so much for your detailed answers!
    – xdyy
    Feb 16 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.