Is there any repeat while

Is there any option to do something like repeat while in the rules? So the following can be simplified?
I want them to flash only for 3 times. Possible to do via introducing input boolean and an automation (something like if input boolean on for 10 seconds - turn the loop script off)
But that looks awkward

light_koridor_flash_green:
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.mys_koridor_37_1
      color_name: "green"
  - delay:
      seconds: 2
  - service: light.turn_off
    data:
      entity_id: light.mys_koridor_37_1
  - delay:
      seconds: 1
  - service: light.turn_on
    data:
      entity_id: light.mys_koridor_37_1
      color_name: "green"
  - delay:
      seconds: 2
  - service: light.turn_off
    data:
      entity_id: light.mys_koridor_37_1
  - delay:
      seconds: 1
  - service: light.turn_on
    data:
      entity_id: light.mys_koridor_37_1
      color_name: "green"
  - delay:
      seconds: 2
  - service: light.turn_off
    data:
      entity_id: light.mys_koridor_37_1

You can’t using YAML, but if you want more versatility and the ability to loop, take a look as AppDaemon.