Copy and Paste both the scripts and run it in master database.
I prefer using WHILE Loop as a better programming practice always suggest writing scripts with Less Line Of Codes (if possible) and also use of CURSOR is reducing now due to higher consumption of MEMORY and if someone misses to include Deallocate Cursor it can still grab the memory and wont release.