Of course an if statement cost time, although very little. However, it changes (although once), so if you need to vary depending on the value, you have to use the if statement.
A while(true) also cost a little time (a little bit less), but less than 1 us, same as the if statement. You can do perfectly do an if statement within the while(true), but remember, the loop itself is behaving like a while(true) already.
However, I wouldn't concern at all about optimizing performance, unless:
- You know beforehand you will need the fastest code possible
- You have already performance issues
Always prefer readability/maintainability about performance.