% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%

%% foreach
%% http://tex.stackexchange.com/a/126418/16595
%% instead of \foreach \var in {start, start + delta, ..., end}
%% this allows to use \foreach[use int={start to end step delta}] without(!) a list in {}
%% the values start, end and delta are evaluated by PGFmath at the start of the loop.
%% In addition to use int, there's also use float.
\newif\iftikzext@pgf@foreach@no@list
\pgfqkeys{/pgf/foreach}{
  normal list/.code={%
    \tikzext@pgf@foreach@no@listfalse
    \def\pgffor@scan{\pgfutil@ifnextchar({\pgffor@scanround}{\pgffor@scanone}}%
  },
  no separator/.code={% token for token
    \def\pgffor@scan@custom##1{%
      \def\pgffor@value{##1}%
      \pgffor@scanned
    }%
    \def\pgffor@scan@custom@comma,{%
      \pgfutil@ifnextchar\pgffor@stop
        \pgffor@scanone
        {\pgffor@scan@custom,}%
    }%
    \def\pgffor@scan{%
      \pgfutil@ifnextchar,%
        \pgffor@scan@custom@comma
        {%
          \pgfutil@ifnextchar\pgffor@stop
            \pgffor@scanone
            \pgffor@scan@custom
        }%
    }%
  },
  use int/.code={%
    \tikzext@pgf@foreach@no@list@parse@to\pgfmathtruncatemacro#1\pgffor@stop
  },
  use float/.code={%
    \tikzext@pgf@foreach@no@list@parse@to\pgfmathsetmacro#1\pgffor@stop
  }
}

\def\tikzext@pgf@foreach@no@list@parse@to#1#2to#3\pgffor@stop{%
  \tikzext@pgf@foreach@no@listtrue
  #1\foreachStart{#2}%
  \pgfutil@in@{step}{#3}
  \ifpgfutil@in@
    \tikzext@pgf@foreach@no@list@parse@step{#1}#3\pgffor@stop
  \else
    \tikzext@pgf@foreach@no@list@parse@step{#1}#3step1\pgffor@stop
  \fi
  \edef\tikzext@pgf@foreach@no@list@list{\foreachStart,\foreachSecond,...,\foreachEnd}%
}
\def\tikzext@pgf@foreach@no@list@parse@step#1#2step#3\pgffor@stop{%
  #1\foreachEnd{#2}%
  #1\foreachSecond{\foreachStart+#3}%
}
\def\pgffor@vars{%
  \pgfutil@ifnextchar i{\pgffor@@vars@end}{%
    \pgfutil@ifnextchar[{\pgffor@@vars@opt}{%]
      \pgfutil@ifnextchar/{\pgffor@@vars@slash@gobble}{%
         \iftikzext@pgf@foreach@no@list\expandafter\pgfutil@firstoftwo\else
           \expandafter\pgfutil@secondoftwo\fi
         {\tikzext@pgf@foreach@no@listfalse\pgffor@macro@list\tikzext@pgf@foreach@no@list@list}
         {\pgffor@@vars}}}}}%

\endinput