How to remain inside a function?

That's just how structured programming was designed. If you want to stay inside the loop forever, then encapsalate the code within the function in a while (1) { } although I can't imagine their are many circumstances where that's actually what is wanted.

if (i = 1){

Not how you write an if statement.
= is assignment
== is equivalence