My program stops before checking the while loop condition?

My program stops before checking the while loop condition
while (c1> 1 * 10 ^ -2) && (c2> 1 * 10 ^ -1) && (iter <= 1) {}
when the program stops I have the following values: c1=0.012, c2=0.074 and iter = 1.
Thanks.

 Réponse acceptée

Walter Roberson
Walter Roberson le 30 Juin 2016
c2> 1 * 10 ^ -1 is not true for c2 = 0.074

3 commentaires

Thanks Roberson. But c1 is greater than 10 ^ -2. I want all these conditions will be checked before leaving the loop.
You used && so the condition is only true if all parts of it are true. One part of it is false, so the entire condition is false. If you want to execute the body of the loop if any of the conditions are true, then use || instead of &&
Thanks for your help Roberson.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by