function y=sum_of_even_squares(limit)
% Using Matlab, write a function 'calculate the sum of squares of all even numbers 
% between 2 and n. hints, the shortest version
% is with a for-loop; but you may try while and if combinations as well; 
% define a variable 'result' to which you add 
% the squared numbers at each step.

%if we get input that's not defined we should tell someone about it.
if( ~isnumeric(limit) )
    error(sprintf('ERROR (%s): parameter must be numeric (integer). We''re aborting here!', mfilename));
    return
end

% initialize the result to zero (is returned as 0 in case of limit <2)
y = 0;

% Check whether input fulfills requirements to be >=2.
% If not, no work is required; leave a note and return 0.
if(limit < 2)
    disp(sprintf('Warning (%s): limit should be >=2; returning 0.', mfilename));
    return
end

% initialize counter to 2; increment by 2 until we reach the limit. 
% square the counter variable (even number) and add it to the old 
% value of y (from last iteration); assign new value to y.
% do this until n>limit.
for n=2:2:limit
    y = y + n^2;
end

% disp(y);

% OR THE SHORT VERSION: 
% create array of even numbers, square each value, sum the values.
% this version can lead to memory issues for large limits, though.
% interestingly enough the runtime of this seems to be larger than
% the for loop; most likely because a huge chunk of memory is
% assigned rather than only scalars (this is rare in Matlab!)
y = sum([2:2:limit].^2);

%disp(y);

return