Restart/Sleep timer can't work

Hi all, I’m an AppleScript beginner, a rookie, I feel AppleScript is too difficult to study. Some one can help me?

I want to script make Mac can run restart/sleep action, and iteration can be set by user enter then record run times as log file.
But I just run only 1 loop and stop.


display dialog "Choose a job :" buttons {"Restart", "Sleep", "Cancel"} default button "Cancel"
set the button_returned to the button returned of the result

if the button_returned is "Restart" then
	---set i to 0
	----repeat until i > 3
	tell application "Finder"
		restart
	end tell
	----	set i to i + 1
	---	end repeat
	
else if the button_returned is "Sleep" then
	---set i to 0
	---repeat until i > 3
	tell application "Finder"
		sleep
	end tell
	----	set i to i + 1
	----end repeat
	
else
	
end if

Model: MacBook (White)
Browser: Safari 525.28.3
Operating System: Mac OS X (10.5)

Once you tell the Finder to restart, it will restart the computer and when you log back in, the script won’t be running.

When you tell Finder to sleep, it will sleep, but your script ends there. If you want to have the script still running when the computer wakes up, you must save the script as an application that stays open. Go to FILE - SAVE AS. Change the type to “application” and click the checkbox that says “stay open.” In order for that to work, you also need to put the whole script in a repeat loop like this:

set theResult to ""
repeat until theResult is "cancel"
	set theResult to display dialog "Choose a job :" buttons {"Restart", "Sleep", "Cancel"} default button "Cancel"
	set the button_returned to the button returned of the result
	
	if the button_returned is "Restart" then
		---set i to 0
		----repeat until i > 3
		tell application "Finder"
			restart
		end tell
		----	set i to i + 1
		---	end repeat
		
	else if the button_returned is "Sleep" then
		---set i to 0
		---repeat until i > 3
		tell application "Finder"
			sleep
		end tell
		----	set i to i + 1
		----end repeat
		
		--You don't need the "else" portion, since it does nothing		
		
	end if
end repeat

Hi Kevin, thanks for your help,
I want to how to edit script to restart/sleep Mac automatically.
and then save log file in the desktop, for I check how many times restart/sleep successful.
BTW, I just what to know, which way can let script execute restart/sleep match user ask.

Maybe, user can type how many times need to run