Borrar filtros
Borrar filtros

How can I make a for loop a while loop?

1 visualización (últimos 30 días)
Susana Salinas
Susana Salinas el 5 de Feb. de 2020
Respondida: Susana Salinas el 5 de Feb. de 2020
x57a= [];
for i= 1:1000
if rem(i,5) ==0 || rem(i,7) ==0
if rem(i,5)==0 && rem(i,7) ==0
continue;
end
x57a = [x57a, i];
end
end
I wrote this code as a for loop but I want to know how it would look like as a while loop

Respuesta aceptada

Bhaskar R
Bhaskar R el 5 de Feb. de 2020
x57a= [];
i = 1;
while i<= 1000
if rem(i,5) ==0 || rem(i,7) ==0
if rem(i,5)==0 && rem(i,7) ==0
i = i +1;
continue;
end
x57a = [x57a, i];
end
i = i+1;
end

Más respuestas (1)

Susana Salinas
Susana Salinas el 5 de Feb. de 2020
Thanks!

Categorías

Más información sobre Problem-Based Optimization Setup 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