MATLAB: How to create a loop that goes up by 5 until a certain number and then up by 3

changing values inside loopsfor loopif looploops

2 parts – 1st: create a loop that goes up by 5 from 12 until 50 2nd: change the loop when the variable is greater than 31 the numbers go up by 3.
I've attempted:
for i=12:5:50
if i>31
disp(i(i=numel(i):3:50))
end
end
and:
j=12:3:50;
for i=12:5:numel(j)
if i>31
disp(i(j))
end
end
and so many other variations .. I've been on the question for hours and feel as though I'm about to go insane.. Please help!!

Best Answer

a = 12;
b = 50;
n = 31;
ii = 5;
while a(end) < 50
if a(end) > 31
ii = 3;
end
a = [a; a(end) + ii];
end