Borrar filtros
Borrar filtros

My program stops before checking the while loop condition?

1 visualización (últimos 30 días)
amine&&
amine&& el 30 de Jun. de 2016
Comentada: amine&& el 1 de Jul. de 2016
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Jun. de 2016
c2> 1 * 10 ^ -1 is not true for c2 = 0.074
  3 comentarios
Walter Roberson
Walter Roberson el 30 de Jun. de 2016
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 &&
amine&&
amine&& el 1 de Jul. de 2016
Thanks for your help Roberson.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by