In the first example you have a loop of order n, and within this loop is another loop of order n (it loops to i, which itself is order n), making the total O(n^2).

In the second example you have a loop of order n, and within this loop another loop of order n, and within THAT loop, you get ANOTHER loop of order n, every other time, which makes the whole thing O(n^3).