After much frustration I am still unsure how to include the while inside the if statement.
It would help if you posted your complete code. Since we have no way of knowing what x_initial is when you start the loop, or what changes it (hint: nothing in the loop changes it), we really can't do much for you.
If you want to post your code, please do the following...
In the IDE
compile your code
hit CTRL-T to format the code
press CTRL-A to select all the code
press CTRL-C to copy it.
In the forum editor window
click on the # icon above the editor window
you will see that the code tags are shown, with the cursor between them
press CTRL-V to paste your code.