clc clear all %% Example 1 with for-end and break disp('Example 1 - The break statement') % The loop below will calculate values of k^2-50 % for all values of the requested k until k^2-50 turns negative for k=-10:1:10 if (k^2-50<0) break end val=k^2-50; fprintf(' k=%g val=%g\n',k,val) end disp(' ') %% Example 1 with while-end disp('Example 1: With the while-end loop') % using the while-end loop to do the same thing as above k=-10; while (k<=10) & (k^2-50>0) val=k^2-50; fprintf(' k=%g val=%g\n',k,val) k=k+1; end disp(' ') %% Example 2 with for-end and continue disp('Example 2 - The continue statement') % The loop below will calculate values of k^2-50 % for all values of the requested k and output only the postive values for k=-10:1:10 if (k^2-50<0) continue end val=k^2-50; fprintf(' k=%g val=%g\n',k,val) end