code for if condition and while loop working