cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Translate the entire conversation x

Skipping steps in looping programatically

terryhendicott
21-Topaz II

Skipping steps in looping programatically

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

ACCEPTED SOLUTION

Accepted Solutions

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

 

 

 

View solution in original post

3 REPLIES 3

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

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

 

 

 

Thanks Werner

Announcements

Top Tags