If you do the program as follows then you will not get null as output:
In this case, your while loop body will not be executed if the token is null. Actually, here the loop condition is
test first and then print the output (execute the loop body) when condition is true, but, in your case the output is printed first (execute the loop body) then test the loop condition for the next iteration.