Explain this while loop
Mostrar comentarios más antiguos
Please explain the steps to how this code fragment works. I don't really understand count or index. Thanks.
What is count as a result of the given Matlab code fragment? Showing your work
may result in partial credit.
numbers = [2 4 3 -5 1 0];
count = 0;
index = 1;
while numbers(index) > 0
count = count + 1;
index = index +1;
end
count = 3
1 comentario
Walter Roberson
el 26 de Feb. de 2013
"count" and "index" are just variable names. You could have used XYZ and Chocolate_IceCream instead and MATLAB would not have cared.
Respuesta aceptada
Más respuestas (1)
Youssef Khmou
el 26 de Feb. de 2013
Editada: Youssef Khmou
el 26 de Feb. de 2013
0 votos
hi Dave :
Literally " Given a vector of length N, count the number of positive elements before the first negative one, as long as the numbers are positive count them but when a <0 number is met, stop the counting"
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!