Modify the following program in order to get rid of the break statement without affecting the behavior of the program
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Taylie Sargent
el 4 de Jul. de 2015
Editada: Geoff Hayes
el 4 de Jul. de 2015
a = rand(1, 10);
index = 1;
while index <= size(a, 2)
if a(index) > .7
break
end;
a(index)
index = index + 1;
end;
0 comentarios
Respuesta aceptada
Nobel Mondal
el 4 de Jul. de 2015
Hi Taylie,
I am not sure why you want the 'break' to be removed. However, the following code works - but NOT an elegant way of doing it.
a = rand(1, 10);
index = 1;
while index <= size(a, 2)
if a(index) > .7
index = size(a,2) + 1;
else
a(index)
index = index + 1;
end
end
Thanks,
Nobel.
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!