BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Language

Setup

  • Getting Started
  • Win32
  • Linux
  • macOS
  • Android
  • iOS
  • Raspberry Pi
  • NX (Switch Homebrew)
  • Custom Settings

Tutorials

  • Beginners Guide
  • OOP Tutorial
  • Network Programming
  • TCP Socket Programming

Language

  • Arrays
  • Basic Compatibility
  • Collections
  • Comments
  • Conditional Compiling
  • Constants
  • Data Types
  • Debugging
  • Enums
  • Exceptions
  • Expressions
  • Functions
  • Identifiers
  • Literals
  • Modules
  • Objects
  • Program Flow
  • Slices
  • Strings
  • User Defined Types
  • Variables
  • Advanced Topics

    • Interfacing With C
    • Memory Management
    • Pointers
    • Custom Pre/Post Compilation Scripts
    • Creating DLLs

Tools

  • MaxIDE
  • BlitzMax Make (bmk)
  • BlitzMax Compiler (bcc)
Edit

Collections

BlitzMax offers simple support for managing collections of objects, and for visiting each object in a collections using a special form of For/Next loop.

The simplest kind of collection is an array:

Local a[]=[1,2,3,4,5]
For Local k=EachIn a
    Print k
Next

Each iteration of such a loop will assign the next array element (starting with element 0) to the index variable before executing the body of the loop. This allows you to visit each array element in turn.

It is also possible to create your own kind of collection with user defined types.

To do this, you must create a user defined type with a method named ObjectEnumerator which takes no parameters and returns an object. The object returned by this method must itself have the following methods:

Method HasNext:Int()        ' returns true if there's a next object
Method NextObject:Object()  ' returns the next object

You can then use the object in a For/EachIn/Next loop:

Local list:TList = New TList

list.AddLast "Hello"
list.AddLast "World!"

For Local t:String = EachIn list
    Print t
Next
← Basic CompatibilityComments →
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2022 Bruce A Henderson