On 3/10/11 4:15 AM, Andrew Wiley wrote:
On Wed, Mar 9, 2011 at 5:19 PM, Joel Christensen<joel...@gmail.com> wrote:
This is on Windows 7. Using a def file to stop the terminal window coming
up.
win.def
EXETYPE NT
SUBSYSTEM WINDOWS
bug.d
import std.stdio;
import std.string;
void main() {
auto f = File( "z.txt", "w" );
scope( exit )
f.close;
string foo = "bar";
foreach( n; 0 .. 10 ) {
writefln( "%s", foo );
f.write( format( "count duck-u-lar: %s\n", n ) );
}
}
output (from in z.txt):
count duck-u-lar: 0
My understanding is that the "0..10" isn't actually a range notation,
and you need to use iota(0, 10). I may be wrong, but if I'm right,
hopefully someone can explain why this syntax works?
I remember there being a discussion about this recently; I'll see if I
can find it.
It works because it's a specialized syntax for foreach. Oh, and I think
in case statements you can use it too, but I don't remember if the first
was inclusive and the second exclusive, or both, or what. But... it just
works for those cases. For the rest you have to use iota...