0

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:)

Nomistake
  • 893
  • 2
  • 17
  • 32
  • First of all, if you want to loop the table once, then why do you want to have a loop? Second, how do you know when there is no data to pass? – funcoding Mar 14 '17 at 11:22
  • Possible duplicate of [Best way to break from nested loops in Javascript?](http://stackoverflow.com/questions/183161/best-way-to-break-from-nested-loops-in-javascript) – Liam Mar 14 '17 at 11:27
  • Hi @Lucero ,is there any example that you can quote me? You do not need to reference to my codings – user7377729 Mar 14 '17 at 11:31
  • Hi @jmmontero , the data is being passed from the form inside view to the database. There are 2 tables and hence I need to loop. – user7377729 Mar 14 '17 at 11:34
  • 1
    I don't understand this language –  Mar 14 '17 at 12:05

0 Answers0