New looping constructs

nxs_loop.h More...

Defines

#define nxs_do_onbreak(_cond, _expr)
 Behaves like a do() loop with the argument _cond, but evaluates _expr only if the loop gets broken out of.
#define nxs_for_eachbreak(_init, _cond, _each)
 Behaves like a for() loop with the arguments _init, _cond, and _each, but evaluates _each even if the loop gets broken out of.
#define nxs_for_onbreak(_init, _cond, _each, _expr)
 Behaves like a for() loop with the arguments _init, _cond, and _each, but evaluates _expr only if the loop gets broken out of.
#define nxs_foreach_array(_var, _array)
 Loops through the items in _array, assigning each to _var and executing the given block of code.
#define nxs_forreach_array(_var, _array)
 Loops in reverse through the items in _array, assigning each to _var and executing the given block of code.
#define nxs_while_onbreak(_cond, _expr)
 Behaves like a while() loop with the argument _cond, but evaluates _expr only if the loop gets broken out of.

Detailed Description

nxs_loop.h

Created by Justin Spahr-Summers on 2007-12-09. Copyright 2007. All rights reserved.


Define Documentation

#define nxs_do_onbreak ( _cond,
_expr   ) 

Behaves like a do() loop with the argument _cond, but evaluates _expr only if the loop gets broken out of.

See also:
nxs_for_onbreak

#define nxs_for_eachbreak ( _init,
_cond,
_each   ) 

Behaves like a for() loop with the arguments _init, _cond, and _each, but evaluates _each even if the loop gets broken out of.

 // utterly useless piece of code... never do this
 // the good news is that it will never leak resources
 unsigned char *ptr;
 nxs_for_eachbreak (
      ptr = NULL,
      (ptr = malloc(rand())),
      free(ptr))
 {
      printf("Allocated %p\n", ptr);
      if (*ptr == 0) {
           printf("Found a zero byte, dying\n");
           break;
      }
 }

See also:
nxs_for_onbreak

#define nxs_for_onbreak ( _init,
_cond,
_each,
_expr   ) 

Behaves like a for() loop with the arguments _init, _cond, and _each, but evaluates _expr only if the loop gets broken out of.

 // utterly useless piece of code... never do this
 // the good news is that it will never leak resources
 char buf[1024];
 size_t size = 0;
 nxs_for_onbreak (
      FILE *fd = fopen("text.txt", "r"),
      size < 1024,
      size = strlen(buf),
      fclose(fd))
 {
      if (!fgets(buf, 1024 - size, fd))
           break;
 }

See also:
nxs_do_onbreak nxs_for_eachbreak nxs_while_onbreak

#define nxs_foreach_array ( _var,
_array   ) 

Loops through the items in _array, assigning each to _var and executing the given block of code.

 int array[] = { 31, 8, 903, -11 };
 nxs_foreach_array (int i, array) {
      printf("%i\n", i);
 }

Note:
This will only work on arrays defined in the current scope.
See also:
nxs_forreach_array

#define nxs_forreach_array ( _var,
_array   ) 

Loops in reverse through the items in _array, assigning each to _var and executing the given block of code.

 int array[] = { 31, 8, 903, -11 };
 nxs_forreach_array (int i, array) {
      printf("%i\n", i);
 }

Note:
This will only work on arrays defined in the current scope.
See also:
nxs_foreach_array

#define nxs_while_onbreak ( _cond,
_expr   ) 

Behaves like a while() loop with the argument _cond, but evaluates _expr only if the loop gets broken out of.

See also:
nxs_for_onbreak


Generated on Thu Dec 20 13:42:46 2007 for NXS Toolkit by  doxygen 1.5.4