EDIT:
Let's look at while(n <= 0)
and while(n < 1)
. These are essentially the same, because both excludecheck for 0 and negative numbers. n <= 0
simply specifies to check if n is less than or equal to 0., while n < 1
states to checkchecks if n is less than 1, which includes 0 and negative numbers. As you can see, they are essentially the same.
However, if it was n >= 0
and n > 1
, these would be different. In n >= 0
, it is checking if n is greater than or equal to 0. This includes 0, 1, 2, 3, and so on. In n > 1
, it checks if n is greater than 1. This includes 2, 3, 4, and so on, but NOTnot 0 or 1. Basically, theThe difference is that n >= 0
includes 0 and 1 while n > 1
doesn't.
Now, why are only (as you said in your comment) n >= 0
and (as CliffB said) n <= 0
valid for floats? In n >= 0
, numbers like 0.1, 0.2, 0.3, and so on count because these numbers are, in fact, greater than 0. But in n > 1
, numbers like 0.1, 0.2, 0.3, and so on will NOT count because these numbers are not greater than 1. The same goes for n <= 0
- numbers like -0.1, -0.2, and -0.3 will count because these are less than 0, while if you use n < 1
, these numbers will not count because they aren't less than 1.
If you still have issues/questions, comment below. :-)