Continuity on a union Let $X= \bigcup X_n$ be a countable union of subsets $X_1\subset X_2\subset \dots$ and let $X$ and $Y$ be topological spaces. Given a function $f\colon X\to Y$ such that $f|_{X_n}$ is continuous, is it necessarily true, that $f$ is continuous on $X$?
I have been trying to think of a counter-example but could find one although it does not quite seem to be enough information on $f$ for it to be continuous. First of all I am interested in a proof or counter-example for this statement, but after all I am also looking for a maybe similar statement that is true.
Edit: If I understood both answers right, additionally assuming that all closures $\bar X_n= X$ would suffice for the assertion?
 A: This is true for all spaces $Y$ if and only if $X$ has the colimit topology with respect to the spaces $X_i$, more traditionally known as the coherent topology. A counterexample is given by a countable set $X$ equipped with the cofinite topology and $X_i$ an increasing sequence of finite sets whose union is $X$ (for example $X = \mathbb{Z}, X_i = [-i, i]$). The colimit topology with respect to the $X_i$ is the discrete topology. 
Edit: $\overline{ X_i} = X$ (which is equivalent to $\overline{ X_1 } = X$) is also not enough to guarantee that you have the coherent topology. Take the above example $X = \mathbb{Z}, X_i = [-i, i]$ with the cofinite topology and remove all of the non-empty open sets that don't include $\{ 0 \}$ (so a combination of the cofinite topology and the particular point topology). Then each $X_i$ is dense but the above problem still stands: the colimit topology with respect to the $X_i$ is the particular point topology on $\{ 0 \}$. 
A: No, it's not true. Take $f(0) = 0$ and $f(x) = 1$ if $x \neq 0$. If $X_{n} = \{0,\frac{1}{n},\frac{1}{n-1},\ldots,1\}$ and  $X = \bigcup_{n} X_n$ is viewed as a subset of $\mathbb{R}$ then $f|_{X_n}$ is definitely continuous, but $f$ is clearly not continuous as a function $f:X \to \mathbb{R}$.
In fact, in order for your condition to hold for all $f: X \to Y$, where $Y$ is allowed to be any space, it is necessary and sufficient that your space $X$ be equipped with the final topology induced by the inclusions $X_{i} \to X$.
A: If it helps, I worked out a special case of this problem, where $X$ is a metric space and $Y=\mathbb{R}$. Then having each $X_n$ be open is necessary and sufficient. 
