How can I avoid duplicating code? Development vs deployed code

I have some code similar to this:

on run ()
	tell application "Google Chrome" to launch
	repeat --infinitely when deployed, but only once or twice when developing
		-- here are maybe 50 lines of code, including a lot of calls to handlers
	end repeat
end run

I want this code to execute differently in two ways depending on whether I develop or if it is deployed:

  1. The deployed version should run continuously
  2. 20-25 % of the code in the middle (the 50 lines) shouldn’t be run when I’m testing while I develop.

I develop and deploy on different machines, therefore (2) can be handled with something like this surrounding code that only should be executed when deployed

if (computer name of (system info)) is "deploymachine" then
	--code that only should be ran when deployed
end if

but that doesn’t work when I want to execute

repeat

or

repeat 3 times

(with corresponding end repeat)

depending on if it is deployed or in development.

I could create two handlers main-deployed and main-development and call them early on in the main-handler but that would require me to duplicate a lot of code, and there are a lot of code changes in the main loop, which would force me to continuously sync changes between these two handlers.

Are there some smart ways around this?

First, since you develop on one machine, but may deploy on several, I would trigger the repeat decision (before the repeat loop) on the identity of the development machine, and assign the result to is_development.
Then:

set repeat_counter to 0
repeat while repeat_counter <3
if is_development then set repeat_counter to repeat_counter + 1

 Your code here

end repeat

Put your code that would be “duplicated” in its own function and call it from where it
Would normally be

on duplictateCode()
—your code
end duplicateCode