Ask Question

Convert for loop to while loop, that is the script

z1=zeros (10);

for x=1:10

for y=1:10

z1 (x, y) = x^2-3*y

end

end

z1

+4
Answers (1)
  1. 23 May, 18:36
    0
    To convert for loop to while loop we have to first declare and initialize the integers or variables that will work as an counter.

    script will be

    z1=zeros (10);

    x=1

    while x<10

    y=1

    while y<10

    z1 (x, y) = x^2-3*y

    y=y+1

    end

    x=x+1

    end

    z1

    Remember that we have to update the counter every time that we not need to be done for loop.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Convert for loop to while loop, that is the script z1=zeros (10); for x=1:10 for y=1:10 z1 (x, y) = x^2-3*y end end z1 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers