Would you ever stop rolling the die? You have a six-sided die. You keep a cumulative total of your dice rolls. (E.g. if you roll a 3, then a 5, then a 2, your cumulative total is 10.) If your cumulative total is ever equal to a perfect square, then you lose, and you go home with nothing. Otherwise, you can choose to go home with a payout of your cumulative total, or to roll the die again.
My question is about the optimal strategy for this game. In particular, this means that I am looking for an answer to this question: if my cumulative total is $n$, do I choose to roll or not to roll in order to maximize my cumulative total? Is there some integer $N$ after which the answer to this question is always to roll?
I think that there is such an integer, and I conjecture that this integer is $4$. My reasoning is that the square numbers become sufficiently sparse for the expected value to always be in increased by rolling the die again.
As an example, suppose your cumulative total is $35$. Rolling a $1$ and hitting 36 means we go home with nothing, so the expected value of rolling once is:
$$E(Roll|35) = \frac 0 6 + \frac {37} 6 + \frac {38} 6 + \frac{39} 6 + \frac {40} {6} + \frac{41}{6} = 32.5$$
i.e.
$$E(Roll|35) = \frac 1 6 \cdot (37 + 38 + 39 + 40 + 41) = 32.5$$
But the next square after $35$ is $49$. So in the event that we don't roll a $36$, we get to keep rolling the die at no risk as long as the cumulative total is less than $42$. For the sake of simplification, let's say that if we roll and don't hit $36$, then we will roll once more. That die-roll has an expected value of $3.5$. This means the expected value of rolling on $35$ is:
$$E(Roll|35) = \frac 1 6 \cdot (40.5 + 41.5 + 42.5 + 43.5 + 44.5) = 35.42$$
And since $35.42 > 35$, the profit-maximizing choice is to roll again. And this strategy can be applied for every total. I don't see when this would cease to be the reasonable move, though I haven't attempted to verify it computationally. I intuitively think about this in terms of diverging sequences.
I recently had this question in a job interview, and thought it was quite interesting. (And counter-intuitive, since this profit-maximizing strategy invariably results in going home with nothing.)
 A: How to use your observation in general:
Just checking things for $35$ isn't indicative of the general case, which for large values is different. Take your argument and use a general square $n^2$.
Suppose you're at $n^2-1$. You can leave with $n^2-1$, or you can roll. On a roll, you lose everything with probability $\frac{1}{6}$. With probability $\frac{5}{6}$ you'll get at least $(n+1)^2-6 = n^2 + 2n - 5$ by rolling until it isn't safe to any more. So, for a simple lower bound, we want to know if $\frac{5}{6}(n^2 + 2n - 5)$ is greater than $n^2-1$. For large $n$, this is not the case, and we can actually get an upper bound by similar reasoning:

An upper bound:
[A tidied up version of the original follows. Keeping the original upper bound would have required a few extra lines of logic, so I've just upped it slightly to keep it brief.]
An upper bound: Suppose we're between $n^2-5$ and $n^2-1$. If we roll, the best things could go for us would be to lose $\frac{1}{6}$ the time, and, when we don't lose, we get in the range $(n+1)^2-6$ to $(n+1)^2-1$ (the highest we could get without taking another risk). Just comparing current valuation, you're trading at least $n^2-5$ for at most $\frac{5}{6}(n^2 + 2n)$ by the time you get to the next decision. The difference is $-\frac{1}{6}n^2 + \frac{5}{3}n + 5$. For $n \geq 13$ this is negative. So if you're at $13^2-k$ for $1 \leq k \leq 6$, don't roll. (Higher $n$ making this difference even more negative gives this conclusion. See next paragraph for details.)
Extra details for the logic giving this upper bound: Let $W_n$ be the current expected winnings of your strategy for the first time you are within $6$ of $n^2$, also including times you busted or stopped on your own at a lower value. The above shows that, if your strategy ever includes rolling when within $6$ of $n^2$ for $n \geq 13$, then $W_{n+1}$ is less than $W_n$. Therefore there's no worry about anything increasing without bound, and you should indeed never go above $168$.

An easy lower bound (small numbers):
Low values: For $n = 3$ we have $(5+6+7+8)/6 > 3$ so roll at $n = 3$. Except for the case $n = 3$, if we roll at $n$, we'll certainly get at least $\frac{5}{6}(n+3)$. So if $\frac{5}{6}(n+3) - n > 0$, roll again. This tells us to roll again for $n < 18$ at the least. Since we shouldn't stop if we can't bust, this tells us to roll again for $n \leq 18$.

An algorithm and reported results for the general case:
Obtaining a general solution: Start with expected values of $n$ and a decision of "stay" assigned to $n$ for $163 \leq n \leq 168$. Then work backwards to obtain EV and decisions at each smaller $n$. From this, you'll see where to hit/stay and what the set of reachable values with the optimal strategy is.
A quick script I wrote outputs the following: Stay at 30, 31, 43, 44, 45, 58, 59, 60, 61, 62, and 75+. You'll never exceed 80. The overall EV of the game is roughly 7.2. (Standard disclaimer that you should program it yourself and check.)
A: The game can be boiled down to the decision near each square. Should one decide to try and overcome the the square, there is (once you passed 9) a fixed chance of success, let's call it $p$ (it can be calculated exactly, but that is not important here).
We first consider the game without the loss, so if we hit the square we just go home keeping the money so far earned.
In that case you of course would never stop rolling. But we can show, that the expected value is nevertheless finite: For everytime we get over a square $n^2$ we secure the difference to the next square $(n+1)^2$ as a payout. This payout amounts to $(n+1)^2-n^2=2n+1$.
Consequently the expected value would be about $\sum_{n=1}^{\infty}(2n+1)p^n$. This a convergent sum.
If we want to know the expectation under the condition that we already overcame $m$ squares, it is $W_m=\sum_{n=1}^{\infty}(2(n+m)+1)p^n$, that is what the future is "worth".
If we now switch back to the other game, where continuing is not free, but incurres an ever rising cost (the probability-weighted cost at each square is  $C_m=m^2(1-p)$ as $m^2$ is the amount we would have to give up, if we hit the suare $m^2$, and $(1-p)$ is the chance to actually hit it), that is the "cost" we have to pay for the future.
We now just have to compare the "worth of the future" we calculated with the "cost of the future".
The worth of the future $W_m$ increases linearly in $m$ (meaning from decision to decision), while the probability weighted cost to continue the game $C_m$ increases quadratically in $m$ (meaning from decision to decision).
So the answer is: Yes, you would stop rolling the die at some point as the expected cost of staying in the game will overtake the expected gain at some point.
A: I'm not sure about the precise value of the chance to hit a given integer given persistent consecutive dice rolls (I may edit it in for the sake of being exhaustive), but it's certain to converge towards some constant past 9 as the distance between square numbers becomes greater than the range of the die. You can brute force the probabilities below 9, but the EV is always going to be lower so there's not any point in doing so.
This is because this problem is a variant of the St Petersburg paradox (http://en.wikipedia.org/wiki/St._Petersburg_paradox) in which the value of the reward grows without bound at a rate faster than the chance of the reward; you can expect to win infinite money with repeated play. In this case, your chance for hitting any given square number grows slower than the quadratically growth of the reward, meeting the conditions for the paradox.
A number of proposed solutions exist but the problem does occasionally attract new discussion and does not yet have a definitive resolution.
A: If you keep rolling the die forever, you will hit a perfect square with probability 1. Intuitively, every time you get close to a square (within distance 6), you have a 1/6 chance to hit the square. This happens infinitely many times, and so you're bound to hit a square eventually.
Slightly more formally, suppose that you roll the die infinitely often whatever happens. Your trajectory (sequence of partial sums) has the property that the difference between adjacent points is between $1$ and $6$. In particular, for each number $N$, there will be a point $x$ in the trajectory such that $N-6 \leq x < N$. If $x$ is the first such point, then you have a chance of $1/6$ to hit $N$ as your next point. Furthermore, if $N_2 > N_1+6$, then these events are independent. So your probability of hitting either $N_1$ or $N_2$ at the first shot once "in range" is $1-(5/6)^2$. The same argument works for any finite number of separated points, and given infinitely many points, no matter how distant, we conclude that you hit one of them almost surely. 
A: If you denote the expected gain of all future throws when you already have cumulated $X$ and throw a $Y$ by $G(X,Y)$, then this is:


*

*$G(X,Y) = $undefined, if $X$ is a square. (Not relevant, but I just mention it.)

*$G(X,Y) = -X$, if $X$ is not a square but $X+Y$ is a square.

*$G(X,Y) = Y+MAX\left(0,\frac{1}{6}\sum_{i=1}^6 G(X+Y,i)\right)$ otherwise.


The first two are easy to see, in the last one the sum calculates the expected gain of all future throws excluding this throw, and the maximum with 0 is taken because you only continue playing if your expected future gain is positive.
I have made an excel table of this, with $1\le Y \le 6$ and $1\le X \le 188$. I have found that by increasing the upper bound for $X$, the expected values for lower $X$ don't change; with the upper bound of $188$ I trust all values up to $160$ (but I have no proof).
In this table, the expected gain is negative for $X=30, 31, 43, 44, 45, 58, 59, 60, 61, 62, 75, 76, 77, 78, 79, 80, \ldots$. I stop here, because these are six consecutive numbers, and to reach higher numbers you will reach one of them. So, according to my excel-calculations, the optimal strategy is to play until you reach one of the numbers in the list.

Update: I had not seen the update to aes' answer yet, but I see now that we independently arrived to the same set of numbers.
A: Many people discuss here that "the estimated gain of the game is not guaranteed finite." I will prove this part by a very simple argument.
The probability that a particular number is hit is $1/3.5$. Now this is not i.i.d. for pairs of numbers, but we always get at least $1/6$ for any conditional probability $P(\text{hit $k$}|\text{hit or not hit something given})$.
This means that no matter what is your strategy, you won't gain more than $n^2$ if you gained at least $(n-1)^2$ with probability at least $1/6$. (Either your strategy is to stop, of you lose the game.) Therefore
$$E \leq \frac16\sum n^2(5/6)^n = 330.$$
Needed to say, $330$ is a very optimistic upper bound of course, and anything like this is reachable moreorless only if you know the next number you roll. (Because then you really gain $n^2$ with probability $\sim (5/6)^n$. The true best possible expected gain is much much much lower, as others show.)
A: I'm not great with the maths of this so I decided to try to understand it in my own way - using Excel.
I ran a simulation of this 7776 times. Of these, 2649 games died when a 1 or 4 was rolled straight away. I assume these are of no interest to us since we don't get to make a decision to roll again.
Of the remaining 5127, 457 still failed to make it past 4. So around 8% made a mistake by even taking their 2nd roll - but they should still be included in the analysis in my opinion.
Taking the mean of all these 5127 games, we get 32.419 as the max winnings achieved before dying. This so far away from every other answer. I've been trying to see where I might have gone wrong but I can't see any flaws in my reasoning.
Here is a table of the drop-outs up to 144:

There are only 159 games still running after 144. The highest any managed to achieve was 900 - 1 game.
A: Since, as shown above, the player will eventually land on a perfect square with probability one, the strategy  here will also depend on the player's utility of wealth function. 
