Skip to main content
21-Topaz II
July 31, 2025
Solved

Skipping steps in looping programatically

  • July 31, 2025
  • 2 replies
  • 383 views

Hi,

How can Mathcad 15 skip steps in a loop with skip stepping dictated within the loop?

Capture.JPG

Here increasing i by two inside the loop only affects the one step not the counter i which jumps back to 7?

Capture2.JPG

Any ideas as want to skip one or two loop steps within loop dictated by calculations within the loop.

 

Cheers

Terry

Best answer by Werner_E

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

Werner_E_1-1753991406435.png

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

Werner_E_3-1753991536761.png

Or you may provide the step numbers to be omitted in a vector

Werner_E_5-1753991677622.png

 

 

 

2 replies

21-Topaz II
July 31, 2025

OK got it after posting.

Use a while loop works.

Cheers

Terry

Werner_E25-Diamond IAnswer
25-Diamond I
July 31, 2025

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

Werner_E_1-1753991406435.png

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

Werner_E_3-1753991536761.png

Or you may provide the step numbers to be omitted in a vector

Werner_E_5-1753991677622.png

 

 

 

21-Topaz II
July 31, 2025

Thanks Werner