Basic Matlab help. Can't seem to grasp basic concept

I need help understanding these two questions. I have managed to do all of my assignments in Matlab without using/understanding these type of problems but they are on my midterm review. I have the answers but can't seem to grasp how to arrive at them. I understand how to use while and for loops in the codes that I have written, but can't figure out the answers to these questions. Help with either one would be greatly appreciated!

Question #1

The output of the following code is? Answer is sum=18

n=0;

sum=0;

while n<10

sum=sum+n;

n= n+3;

end

fprintf('sum= %d \n', sum)

Question #2

What is the final value for y in the code below? Answer is -49

Also, how many times will the 'for' loop run? Answer is 7

Here is the code:

y=0;

for x= 1:2:13

y=y-x;

end

Any help will be greatly appreciated. My textbook is pretty useless and I cannot figure these out.