Mar-13-2019, 05:25 PM
Hi, I just want to know that why we don't use == operator with while / for loop?
Help required over a confusion
|
Mar-13-2019, 05:25 PM
Hi, I just want to know that why we don't use == operator with while / for loop?
Mar-13-2019, 05:33 PM
Feel free to use == any where an equality check is needed.
Thanks but pycharm is showing error while using this in a code ;
x=0 while (x>==0): print(x)
Mar-13-2019, 05:46 PM
Because that is not == you want just >= not >==.
Mar-13-2019, 05:52 PM
That's the reason i m getting confuse ..
scenarios are; 1) if we use while (x==10)----it works perfectly. 20 But if we use while (x<=10)-----this shows error to not to use double is equal to sign. Confusion is why we dont use double == sign while using with another operator whereas if we use == independently then no error...
Mar-13-2019, 05:58 PM
== is used to distinguish the operator from assignment, where = is used. We don't need to distinguish >= from =, because they are obviously different, so we don't use >==.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures
Mar-13-2019, 06:12 PM
Maybe your thinking because < is less than and == is equal that you could combine them to make less than or equal.
They are set symbols that are used individually. #Operation Meaning < #strictly less than <= #less than or equal > #strictly greater than >= #greater than or equal == #equal != #not equal is #object identity is not #negated object identity
Mar-13-2019, 06:56 PM
Thanks Sir, got the point.
|
|