I realized that I didn't reinitialize my "a" variable, thanks to Barmar's comment. Although the code might not look very efficient, this is what works for me:
a = 10;
k = 0.5;
n = 2;
while a < 300
a = 10;
for m = 1:5
a = a + (a*k) + n;
end
if a >= 300
break
end
n = n + 1;
end