This is probably a silly question. I do a lot of data extrapolation with for loops in my applications. In almost all cases I tend to find i <= 2 easier to read/interpret than i < 3. Based on what I know they should always mean the same thing, but I'm wondering if there are special cases where they would be evaluated differently when used in a for loop. For example, if you used ++i instead of i++.
Provided that i is an integer, then the expressions i<=2 and i<3 should be identical in function.
(they may be slightly different in terms of speed performance)
If i has type float, double, decimal, or related, then a value of 2.3 would fail the first test, but pass the second test.
If you specifically overload the operator< or operator<=, then you could make anything possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With