HPInc / HP-Digital-Microfluidics

HP Digital Microfluidics Software Platform and Libraries
MIT License
3 stars 1 forks source link

Add form to get loop iteration counter #306

Open EvanKirshenbaum opened 8 months ago

EvanKirshenbaum commented 8 months ago

Mike needed to do a loop that was essentially

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:

Migrated from internal repository. Originally created by @EvanKirshenbaum on Oct 02, 2023 at 5:02 PM PDT.