Both of those code fragments are doing way too much work. You can replace them with int sum = 40;
(in fact, if you gave those code fragments to a compiler, that's basically what the compiler would do). There's a famous trick for summing up the first n integers I used to do it in my head, but if you didn't know the trick and had no calculator handy, you could work it out with pen and paper in about the same amount of time it would take to type up that code. So the problem, as stated, isn't something you should be writing a program for at all.
Of course, you aren't asking about only that one example problem. What problem are you actually trying to solve? The question overspecifies a bit, so I'll just guess that you're either (a) going for something that sums up all the consecutive integers over a range except for a specified one, or (b) you're going for summing up all the consecutive integers in a range, except for a range in the middle.
If you want (a), then you can just subtract the specified number from the range. If you want (b), then you can break the large range into a bottom half and a top half and deal with each separately. So, in either case, we want something that can sum up a range of integers.
If you know the famous formula for summing up the first n integers (n*(n+1)/2), and you know how it works, it isn't hard to come up with a formula for a range ((top-bottom+1)*(top+bottom)/2). If not, there's the obvious and straightforward way of doing it with for loops.
If we write a function that does that (with either method), we can rewrite the original problem as sum_range(0,9) - 5
or sum_range(0,4) + sum_range(6,9)
. It turns out we didn't need any ifs or continues, and, depending on how we wrote it, maybe no for loop either.
If your question is really about which keyword to use when nested inside a construct using a specific keyword which is nested inside another construct using another specific keyword, then I don't think your question really has an answer, and that trying to figure out how to program by looking at which keywords nest inside which other keywords is never going to be useful.
(For those interested, the formula works like this: say we're trying to add up all the integers from 1 to 100. 1+100 = 101, 2+99 = 101, 3+98 = 101, and so on, so we could just multiply 101 by the number of pairs, and the number of pairs is the number of numbers being added / 2. In this case, top = 100, bottom = 1, top+bottom = 101, and the number of pairs is (top-bottom+1)/2 = n/2 = 50.)