repeat 10 times {
dispense_and_walk_dna(well#4);
}
but he wanted to print out the iteration number, so I had to tell him to do it as
repeat with int iter = 1 to 10 {
print "Dispensing DNA drop "+iter+".";
dispense_and_walk_dna(well#4);
}
It's really annoying that you have to declare a special variable just to hold the iteration count, and it would be even uglier if there were some other loop control, because then you'd need to manage the counter yourself, e.g.,
int iter = 0;
repeat for 10 minutes {
iter = iter+1;
print "Dispensing DNA drop "+iter+".";
dispense_and_walk_dna(well#4);
}
and you'd probably want to enclose the whole thing in braces so that you didn't pollute the outside namespace.
This is ugly. What you want to do is something more like
repeat 10 times {
print "Dispensing DNA drop "+loop iteration+".";
dispense_and_walk_dna(well#4);
}
where the looping mechanism keeps track of the counter for you and there's a special form that retrieves it. This shouldn't be difficult to implement.
Some considerations:
This probably can't be done simply as a special variable, as we'll want to be able to note an error if this is used in a context that isn't statically inside a loop. This will require treating it the way we treat exit statements, checking self.control_stack.in_loop.
Since we have named loops, it would be nice to have the ability to grab the iteration counter for loops that aren't the nearest one. I'm not sure what the syntax would be, but the implementation can probably be straightforwardly reading a variable whose name incorporates the loop name, e.g., **LOOP_outer_ITERATION**.
It's probably not worth it, but if we ever add an indication of external names referenced by a block, it would be a good idea for a loop to not bother creating and updating its counter if its body doesn't refer to it.
Migrated from internal repository. Originally created by @EvanKirshenbaum on Oct 02, 2023 at 5:02 PM PDT.
Mike needed to do a loop that was essentially
but he wanted to print out the iteration number, so I had to tell him to do it as
It's really annoying that you have to declare a special variable just to hold the iteration count, and it would be even uglier if there were some other loop control, because then you'd need to manage the counter yourself, e.g.,
and you'd probably want to enclose the whole thing in braces so that you didn't pollute the outside namespace.
This is ugly. What you want to do is something more like
where the looping mechanism keeps track of the counter for you and there's a special form that retrieves it. This shouldn't be difficult to implement.
Some considerations:
exit
statements, checkingself.control_stack.in_loop
.**LOOP_outer_ITERATION**
.Migrated from internal repository. Originally created by @EvanKirshenbaum on Oct 02, 2023 at 5:02 PM PDT.