So you want to continue the series until 511 right? I think thats what you mean.
Which part of the for loop controls when it stops? Is it right?
Can you think of a better way to write this? Hint put all the calculations involving y in the body of the loop and not in the end condition or increment expression.
I think you should stick to the for loop because it's easier to test for the end condition. Abandon the code you have - it's the wrong approach.
This series only needs 2 numbers to start it off, and you would like another number to specify when the series stops.
I also think you should do a basic design:
Start with a blank file, write comments that specify how you are going to do the problem, like this:
1 2 3 4 5 6
//get first number in the series
//get second number in the series
//get the end number of the series
//use a for loop to calc & print each number in the series up to the end number
then decide what variables and functions you need. You may not need any functions.
Go back and write the code you need, leave the comments they are documentation.
Anther thing - get used to starting with zero not 1, like this:
1 2 3 4
for (int x=0; x < EndNumber; x++) { //hint you will have 2 variables on this line
//do stuff EndNumber times
}