How to cancel the macro if a loop in it completes x repititions?

Have a google for "why is goto bad" (besides that it'll get you eaten by a dinosaur). It can be done well, but more often than not just confuses things further.

What you want to do is sort out your "control flow" -- do it on paper first. You'll then be able to see how to do what you want using a combination of "If", "Repeat", and other KM actions.

For example -- why do you want to start from step 5? If it's a decision based on state, use an "If" statement to not do steps 1-4 if the "start at step 5" conditions apply.

Macroing a complicated process is complicated! And, very often, what seems quite simple to us is actually complicated when viewed from your computer's point of view -- even if just opening a web page and filling in a form, there's a whole bunch of contextual cues we act on without even thinking, but will have to be made explicit in the macro.

Start from the beginning. Do the process manually and write down each and every step you do, each and every decision you take, in performing the process (a good trick is to pretend you are trying to talk someone through the process over the phone). Then, one piece at a time, translate that into KM actions and build up a macro.

You don't need to do it all in one go. A macro that opens a web page, ready for you to fill in a form, is more efficient than no macro. Next step -- use that macro to open the page, you fill in the form manually, then make another macro to submit the form then close the page and mark the job done in your todo list. When you work out how to automate the form-filling, add that and join everything together.