« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

range

#define range(...)

Construct a Range object on the stack.

Examples

Usage

/* Iterate 0 to 10 */
foreach (i in range($I(10))) {
  print("%i\n", i);
}

/* Iterate 10 to 20 */
foreach (i in range($I(10), $I(20))) {
  print("%i\n", i);
}

/* Iterate 10 to 20 with a step of 5 */
foreach (i in range($I(10), $I(20), $I(5))) {
  print("%i\n", i);
}

/* Iterate 20 to 10 */
foreach (i in range($I(10), $I(20), $I(-1))) {
  print("%i\n", i);
}

Range


Integer Sequence

The Range type is a basic iterable which acts as a virtual sequence of integers, starting from some value, stopping at some value and incrementing by some step.

This can be a useful replacement for the standard C for loop with decent performance but returning a Cello Int. It is constructable on the stack with the range macro which makes it practical and easy to use.

Definition

struct Range {
  var value;
  int64_t start;
  int64_t stop;
  int64_t step;
};

Derives

Implements

  • Assignassign
  • Cmpcmp eq neq gt lt ge le
  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Iterforeach iter_init iter_next iter_type
  • Lenlen
  • Newnew del construct destruct
  • Showshow look print scan

Back