Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:14:50+00:00 2026-06-04T13:14:50+00:00

How would I code a function to iterate through one pages worth of data?

  • 0

How would I code a function to iterate through one “pages” worth of data? Sample code would be ideal…

So say we image the size of a page is 5 items. If we had a lua table with 18 items it would need to print out:

  • Page 1: 1 to 5
  • Page 2: 6 to 10
  • Page 3: 11 to 15
  • Page 4: 16 to 18

So assume the data is something like:

local data = {}
data["dog"] = {1,2,3}
data["cat"] = {1,2,3}
data["mouse"] = {1,2,3}
data["pig"] = {1,2,3}
.
.
.

How would one code the function that would do the equivalent of this:

function printPage (myTable, pageSize, pageNum)
  -- find items in "myTable" 
end

So in fact I’m not even sure if a Lua table used as a dictionary can even do this? There is no specific ordering is there in such a table, so how would you be sure the order would be the same when you come back to print page 2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:14:51+00:00Added an answer on June 4, 2026 at 1:14 pm

    The next function allows you to go through a table in an order (albeit an unpredictable one). For example:

    data = { dog = "Ralf", cat = "Tiddles", fish = "Joey", tortoise = "Fred" }
    
    function printPage(t, size, start)
        local i = 0
        local nextKey, nextVal = start
        while i < size and nextKey ~= nil do
            nextKey, nextVal = next(t, nextKey)
            print(nextKey .. " = " .. nextVal)
            i = i + 1
        end
        return nextKey
    end
    
    local nextPage = printPage(data, 2)  -- Print the first page
    printPage(data, 2, nextPage)         -- Print the second page
    

    I know this isn’t quite in the form you were after, but I’m sure it can be adapted quite easily.

    The next function returns the key after the one provided in the table, along with its value. When the end of the table is reached, it returns nil. If you provide nil as the second parameter, it returns the first key and value in the table. It’s also documented in Corona, although it appears to be identical.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have some code to iterate through an XML file recursively like
I would like to play/pause video using jquery. Here is my code: (function ($)
Pseudo code: $(document).ajaxError(function(e, xhr, options, error) { xhr.retry() }) Even better would be some
I'd like to write a function that would have some optional code to be
For some reason the code below when I iterate through some urls, curl_exec never
Would the code bellow cause my code to leak? More specifically, am I responsible
This kind of code would normally work in PHP, but since the scope is
I would like to know if the following code would be a good pattern
I would like to see how this example of existing code would be able
I'm curious if following code would be considered safe? using (SqlConnection cn = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.