for i in range(len(nums)-1): if nums[i] > nums[i+1]: return False # If any element is greater than the next, it's not sorted return True # If the loop completes without out-of-order elements, sorted