X-Git-Url: http://git.harvie.cz/?p=svn%2FCll1h%2F.git;a=blobdiff_plain;f=demos%2Ffor_range.c;fp=demos%2Ffor_range.c;h=c96f24cb53b05768f55c127d1f1010f6246d05c5;hp=44a7b5be881d67ec3a7096e993b40dd8cd55412e;hb=a3c2aecbff1dd82a26f3a69a3e1fdc04349b8d7a;hpb=7bbf75332a1c70ddd99484cba956d8e4df220fb2 diff --git a/demos/for_range.c b/demos/for_range.c index 44a7b5b..c96f24c 100644 --- a/demos/for_range.c +++ b/demos/for_range.c @@ -2,25 +2,50 @@ program { - int i; + int i,j=1; - echo("for_range(i,0,1)"); - for_range(i,0,1) printf(" [%d]",i); + echo("Just plain vanilla auto-increment:\tfor_range(i,1,5)"); + for_range(i,1,5) + { + printf(" [%d]",i); + } print(""); - echo("for_range(i,1,0)"); - for_range(i,1,0) printf(" [%d]",i); + echo("Single-evaluation of macro argument:\tj=1; for_range(i,0,j++)"); + for_range(i,0,j++) + { + printf(" [%d]",i); + } print(""); - echo("for_range(i,1,1)"); - for_range(i,1,1) printf(" [%d]",i); + echo("Just plain vanilla auto-decrement:\tfor_range(i,1,0)"); + for_range(i,1,0) + { + printf(" [%d]",i); + } print(""); - echo("for_range(i,1,5)"); - for_range(i,1,5) printf(" [%d]",i); + echo("Single iteration is possible too:\tfor_range(i,1,1)"); + for_range(i,1,1) + { + printf(" [%d]",i); + } print(""); - echo("for_range(i,5,1)"); - for_range(i,5,1) printf(" [%d]",i); + echo("Yet another example of macro safety:\tj=2; for_range(i,5,--j)"); + for_range(i,5,--j) + { + printf(" [%d]",i); + } + print(""); + + echo("Nesting of this macro seems to be safe:\tfor_range(i,1,3) for_range(j,3,1)"); + for_range(i,1,3) + { + for_range(j,3,1) + { + printf(" [%d,%d]",i,j); + } + } print(""); }