Loop through only part of list?

About Monkey 2 Forums Monkey 2 Programming Help Loop through only part of list?

This topic contains 4 replies, has 4 voices, and was last updated by  nerobot 2 years, 4 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5273

    Pakz
    Participant

    I am creating a listbox and want to use a list. What I do not know how to do is to loop through only a part of the list.

    Say from 10(the top of the window index) to 30(the bottom of the window index)

    What I do not know now is how to get the contents from a list item.

    drawtext Mylist.item[10]

    I do know how to loop through a complete list using eachin.

    #5274

    Pakz
    Participant

    I am looking on google and see that it probably is not possible with linked lists. I will start to look at stack and else I wil use a regular array.

    #5275

    Jesse
    Participant

    To go through a complete list:

    [/crayon]

    There is no simple way to go trough part of the list. list are made to go from the first to the last or vice versa. you can convert it “ToArray” and then index it that way but converting it to array is slow. or you can use an index variable to find the ones you want to process:

    [/crayon]

    or

    [/crayon]
    #5276

    codifies
    Participant

    the more complex version! you can replicate what happens to eachin loop

    If you wanted you could implement a custom iterator too, but in the real world… just do what Jesse suggested…

    #5330

    nerobot
    Participant

    In the latest example we got endless loop. Should replace ‘continue’ with ‘exit’.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.