If you come from a programming background you might want to do a loop using TSQL rather than using a cursor.
The syntax for this is pretty recognisable, exempli gratia,
However if you want to feed in dynamic variables captured from a table you can create a distinctive row count table.
This deduplicates the occurrence of a field value and assigns it a row number.
Where this can be used will be included in a more complicated example coming in the future.