I am trying to convert a for loop to a while loop that will produce the same result. Although I understand the concept, I keep running into an error that I'm not sure how to fix. Any help would be appreciated!
The for loop:
for i = 1:5 x=x+y(i);
And I came up with the while loop:
while i <= 5
However, it keeps giving me the error "Index exceeds the number of array elements (5).
Error in Example (line 6)
I don't understand why this is happening, since the while loop should run 5 times, increasing the i value by 1 each time, and the vector y has 5 elements.
Like I said, any help would be appreciated! Thank you!