uhm..
two ways:
1st:
Your particle emitter code has a while loop. just replace "while(1)" with "while(var == 0)"
When you set the var to a value other than 0, the loop breaks.. particle emitting stops
2nd:
you call the emitting code from another function ( emitting code has no while loop ) every frame.
Then just stop calling the emitting code.