clc clear all disp('ABSTRACT') disp(' Example showing the while-end loop') disp(' ') %% Example 2 - while loop % Purpose: To display only the positive output of y=x^2-49 % as x goes from -10 to 10 x=-10; % Starting point of x disp('OUTPUTS') while (x<=10) y=x^2-49; if (y>0) fprintf(' y=%g, x=%g\n',y,x) end x=x+1; %<- Adding 1 to the count end disp(' ') %% additonal code from what is in book disp('EXTRA EXAMPLE') disp(' Stop loop when y becomes negitive') % Purpose: Output the positive values of y & once negative, stop the loop. x=-10; % Starting point of x disp('OUTPUTS') while (x<=10) & y>0 % x must be less then 10 and y greater then 0 y=x^2-49; % calculate the value of y fprintf(' y=%2g, x=%g\n',y,x) x=x+1; %<- Adding 1 to the count end