Skip to main content
4 of 4
deleted 2 characters in body

Integral of a function defined with a loop

I have defined a function g as

g[t_] := (
   res = 0;
   i = 1;
   While[i <= t,
     res = res + i;
     i = i + 1;
   ];
   res);

The aim is to work with the function F[u], which should be the integral of g in bounds $[0,u]$, something like

F[u_] := Integrate[g[y], {y, 0, u}]

However, the result I obtain for F is not correct with such definition of g. In fact, F takes value 0 for any argument u (my guess is that this happens because g[y] is immediately evaluated as 0).

How can F be redefined properly, without changing the definition of g?