We don't have a sample online, but in Razor (C#) you have LINQ which makes these sorts of things pretty easy:
var pages = Data.Get<IPage>().OrderBy(f=>f.Title).Skip(40).Take(20);
This code grabs pages, orders by the page Title field, skips the first 40 results and takes the next 20 results (so result 41-60).