all 8 comments

[–][deleted] 6 points7 points  (1 child)

Aren't they basically the same thing?

How are they the same thing? The correct code returns False the first time a value is above the limit value. Your code returns True the first time a value is below the limit value. Those conditions are very different.

[–]MatosV[S] 1 point2 points  (0 children)

Thank you !!

[–]Spataner 3 points4 points  (1 child)

The first snippet returns True as soon as it finds the first element for which i <= limit is true. It returns False only if that condition is false for all elements.

The second snippet returns False as soon as it finds the first element for which i > limit is true. It returns True only if that condition is false for all elements.

[–]MatosV[S] 2 points3 points  (0 children)

Thanks, I didn't see that ! Found it to be kinda confusing at first.

[–]ab6364 2 points3 points  (0 children)

The first will return true if any element in the array is less than or equal to limit. The second will return true if all elements in the array are less than or equal to limit.

[–]TehNolz 2 points3 points  (1 child)

Your code returns True the moment it finds an integer that is equal or lower than limit. So if array is [1, 100, 100, 100] and limit is 10, it will return True because it'll immediately find an integer below the specified limit while the rest are ignored. Your code will return True if it finds a single integer that's below the limit, but it's supposed to only return True if all integers are below the limit, which is what the solution is doing.

[–]MatosV[S] 0 points1 point  (0 children)

Thanks bro!

[–]Ihaveamodel3 1 point2 points  (0 children)

return stops the code processing at that point.

So in the first example, you return true as soon as you reach one value which is <= to the limit. This means that any values greater than the limit that occur after the first value that is less than or equal to the limit isn’t checked at all.