Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between evaluation of while(n>0) and while(n!=0)

Is the evaluation of while(n>0) and while(n!=0) different? Basically both are to exit in the same condition. So is there a scenario when one of them should be used? Or will it make a difference in the performance efficiency by changing the loop condition when the number of times the loop being evaluated being the same?

like image 375
Vini Avatar asked Mar 13 '23 20:03

Vini


1 Answers

This depends on your platform, but in general, it will perform identically. For example, for x86 architecture cmp operator will be used for both > or !=. Here you can read more.

like image 122
fedorshishi Avatar answered Mar 19 '23 16:03

fedorshishi