I have a code here which will loop the table once. However, I want to stop the loop if there are no data to be pass to the database. Is there a way to stop the loop? The code is as follow:
if(abcJob.save(flush: true)){
   def xyzTracking
   XYZTracking.withTransaction{
   xyzCreation ->
   while (counter < 2){     
      def Params1 = 'field1'+counter
      def Params2 = 'field2' +counter
      def Params3 = 'field3' +counter
      def Params4 = 'field4' +counter
      xyzTracking =  new XYZTracking()
      xyzTracking.d = params[Params1]
      xyzTracking.e = params[Params2]
      xyzTracking.f = params[Params3]
      xyzTracking.g = params[Params4]
      xyzTracking.abc = abcJob
      xyzTracking.save(flush: true);
      counter++;
   }
}
Thanks in advance. Your help is much appreciated:)
 
    