Author Topic: nested loops  (Read 692 times)

0 Members and 1 Guest are viewing this topic.

n.manu

  • Guest
nested loops
on: Thu, 12. December 2002 - 07:56:49
Hello,

I met a problem with the nested loop in vlib 4.0. I resolved it partially but I would wish to have confirmation.

The template :

Code: [Select]
TMPL_LOOP NAME=block1

  TMPL_LOOP NAME=block2

     TMPL_VAR NAME=variable_1br

     TMPL_VAR NAME=variable_2br

  /TMPL_LOOP

/TMPL_LOOP


First attempt :
Code: [Select]
$tmpl-newLoop'block1';



for$i=1;$i=$arguments'number_of_loops_block_1';$i++



   $tmpl-newLoop'block2';



    for$j=1;$j=$arguments'number_of_loops_block_2';$j++

      

      for$k=1;$k=$arguments'number_of_variables';$k++

      

         $data'variable_'.$k = $k;

      



      $tmpl-addRow$data, 'block2';

    

    

    $tmpl-addLoop'block2';





$tmpl-addLoop'block1';


A warning occur with the message "called vlibTemplate::addRow() or vlibTemplate::addLoop() with an invalid loop name." on the second addLoop.

Second attemp :

Code: [Select]
$data = array;



for$i=0;$i$arguments'number_of_loops_block_1';$i++



  $data$i'block2' = array;

  

  for$j=0;$j$arguments'number_of_loops_block_2';$j++

    

      for$k=1;$k=$arguments'number_of_variables';$k++

      

         $data$i'block2'$j'variable_'.$k = $k;

      

    

  



$tmpl-setLoop'block1', $data;


It's ok .

third attempt :

Code: [Select]
$tmpl-newLoop'block1';



for$i=1;$i=$arguments'number_of_loops_block_1';$i++



   for$j=1;$j=$arguments'number_of_loops_block_2';$j++

    

      for$k=1;$k=$arguments'number_of_variables';$k++

      

        $data'block2'$j'variable_'.$k = $k;

      

    

    

    $tmpl-addRow$data, 'block1';





$tmpl-addLoop'block1';


It's ok.

Question :

As in the first attempt, the third mode for loop (newLoop, addRow, addLoop) is useful with nested loops ?

Best regards,
Manu

releasedj

  • Guest
nested loops
Reply #1 on: Thu, 12. December 2002 - 10:33:57
Hi,

First of all, I didn't manage to reproduce the error that you got with the first example, this example shouldn't work anyway as the 3-step-loop only works with non-nested loops, unless you hack it a little as you did in example 3.

Second of all, in response to your question, the 3-step-loop was made to make non-nested loops, so currently the best way to create a nested loop is with the setLoop() function.

Regards,

Kelvin
PS: keep an eye on the forum as I'm looking at introducing a function to make creating nested loops easily possible with the 3-step-loop method.