Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi,
How can Mathcad 15 skip steps in a loop with skip stepping dictated within the loop?
Here increasing i by two inside the loop only affects the one step not the counter i which jumps back to 7?
Any ideas as want to skip one or two loop steps within loop dictated by calculations within the loop.
Cheers
Terry
Solved! Go to Solution.
I would agree that using a while loop sure is the better idea as i consider it bad habit to manipulate the loop control variable.
But I was surprised about the result - that's sure not what I would have expected
Unlike other programming languages in Mathcad altering the loop control variable within the loop seems to have no effect on the working of the loop. It's like the "i" on the left hand side runs in a different context as the loop control variable "i", similar to local vs. global worksheet variable.
BTW, Prime shows the very same behaviour.
If for some reason you need a for-loop and omit steps if a certain condition is fulfilled, then you can use "continue".
To skip step 6 and 7 (which obviously was your intention in the example) you could do it that way
Or you may provide the step numbers to be omitted in a vector
OK got it after posting.
Use a while loop works.
Cheers
Terry
I would agree that using a while loop sure is the better idea as i consider it bad habit to manipulate the loop control variable.
But I was surprised about the result - that's sure not what I would have expected
Unlike other programming languages in Mathcad altering the loop control variable within the loop seems to have no effect on the working of the loop. It's like the "i" on the left hand side runs in a different context as the loop control variable "i", similar to local vs. global worksheet variable.
BTW, Prime shows the very same behaviour.
If for some reason you need a for-loop and omit steps if a certain condition is fulfilled, then you can use "continue".
To skip step 6 and 7 (which obviously was your intention in the example) you could do it that way
Or you may provide the step numbers to be omitted in a vector
Thanks Werner
