Skip to main content
10-Marble
November 17, 2024
Solved

While Loop with two conditions

  • November 17, 2024
  • 1 reply
  • 1016 views

Hi All,

I am trying to use a While Loop with two conditions, something like below:

while (x > 10) ^ (y < 100)

...

but Mathcad 15 only goes through the loop once and does not execute the iterations. If I use only one condition check, it works fine. Could someone let me know if it is correct to do what I show above?

Thank you.

 

Best answer by LC_12355277

Thanks Werner_E, for your quick response. One of the two conditions is a loop counter. I inadventantly initialized it outside the solve block. After I moved this initialzation into the solve block, it works now. I do not know why that would make a difference. Thanks again, 

1 reply

25-Diamond I
November 17, 2024

Obviously one of your two conditions linked with logical 'and' is not fulfilled after the first loop pass, so that no further passes are made.

To get a qualified answer to your question, you would have to specify in more detail what exactly you are doing and, of course, attach your worksheet here.

LC_1235527710-MarbleAuthorAnswer
10-Marble
November 17, 2024

Thanks Werner_E, for your quick response. One of the two conditions is a loop counter. I inadventantly initialized it outside the solve block. After I moved this initialzation into the solve block, it works now. I do not know why that would make a difference. Thanks again, 

25-Diamond I
November 17, 2024

@LC_12355277 wrote:

Thanks Werner_E, for your quick response. One of the two conditions is a loop counter. I inadventantly initialized it outside the solve block. After I moved this initialzation into the solve block, it works now. I do not know why that would make a difference. Thanks again, 


Frankly, I can't make much sense of your description of the situation and I don't know how your question about a while loop suddenly has anything to do with solve block.
Therefore, I can't say anything about why the assignment to a worksheet variable changes the behavior of your program.