WeBWorK Problems

If / else loops and wanting to skip numbers

Re: If / else loops and wanting to skip numbers

by Danny Glin -
Number of replies: 0
It looks like you are trying to do things in groups of three. Rather than nesting an if/else statement inside a loop, you could set three consecutive values in each loop iteration. Consider the following:

for $i (0..7) {
do stuff to 3*$i;
do stuff to 3*$i+1;
do stuff to 3*$i+2;
}

This would be a little bit more efficient than what you have written. For small numbers of iterations, you probably won't notice a difference, but it can start to slow things down if the situation gets large.