The numbers come from a list's indexes that a user selected in UI. Actually I want to see if he selects a consecutive rows or not. Is there any way (sure there is :)) to check this without walking through all items in the list? I mean for example by using the first and last number in the list etc?

On second thought, I kind of dislike the formulation of the assumptions. That we are concerned with integers is explicitly specified by the OP. Furthermore, there seems to be a mix up between what is the desired result and what we can assume about the input list. If the desired result is for a list like {1,1} we should give true, then the code with Last, First and Length is useless. If not, then it will yield the right result whenever the list is non-decreasing, that is it works even if there are repeats. In this case you give False for {1,1} as desired.
–
Jacob AkkerboomDec 21 '13 at 17:09

Very clean, and I can't think of anything wrong with it at the moment. Theoretically it will be a bit slower on long lists that would be eliminated by one of my "sanity checks" but it probably doesn't matter in practice.
–
Mr.Wizard♦Dec 21 '13 at 13:57

It checks for consecutive numbers in either direction. It however will consume memory our outright fail in the case where the first and last values in the test list are far apart because of the Range generation:

Range[##, Sign[#2 - #]]& @@ #[[{1, -1}]] == # &[{1, 2, 1*^50}]

Range::range: Range specification in Range[1,100000000000000000000000000000000000000000000000000,1] does not have appropriate bounds. >>

If you don't mind, why not? There is no specific constraint on the size of the last integer in the list, so it seems like a valid concern.
–
Mr.Wizard♦Dec 21 '13 at 13:58

It is generally the case that Mathematica can not handle numbers or list lengths beyond certain limits. By default, I prefer to look for a simple solution within these constraints. If I were a NASA engineer or a microchip designer, I would probably take a different stance.
–
David CarraherDec 21 '13 at 14:05

1

@Mr.Wizard There is an implicit constraint in that the OP said that the indices come from selections a user makes in a UI. Now if you want to argue that the UI might have $10^{10}$ rows and we need to optimize for that, then that's silly.
–
The Toad♦Dec 21 '13 at 17:52

I should mention here that my previous comment doesn't hold if we make the assumptions in the update posted (a short while ago) by OP in his question. (Although in that case there are much simpler ways of testing, as already indicated in other answers.)
–
AkyDec 21 '13 at 21:53

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.