fork download
  1. // whileloop.d
  2. // while..loop and do..while examples in D
  3. // To Compile: C:\dmd\MKoD_ex>..\bin\dmd whileloop.d
  4. private import std.stdio;
  5.  
  6. int main()
  7. {
  8. int ix = 0;
  9.  
  10. writefln( "while..loop 1 to 10 (is using main's ix, which equal 0)" );
  11. while ( ix < 10 )
  12. writefln( " ix=%d", ++ix ); //pre-addition happens before it's printed
  13.  
  14. writefln();
  15.  
  16. writefln( "while..loop 10 to 1 (is using main's ix, which now equals 10)" );
  17. while ( ix > 1 )
  18. writefln( " ix=%d", --ix ); //pre-subraction happens before it's printed
  19.  
  20. writefln();
  21.  
  22. ix = 0;
  23. writefln( "do..while loop, 1 to 10 step by 2" );
  24. do
  25. {
  26. ix += 2;
  27. writefln( " ix=%d", ix );
  28.  
  29. } while ( ix < 10 )
  30.  
  31. writefln();
  32.  
  33. ix = 0;
  34. writefln( "forever while..loop, that breaks out on 10" );
  35. while ( true )
  36. {
  37. ix++;
  38. writefln( " ix=%d", ix );
  39. if ( ix == 10 ) break;
  40. }
  41.  
  42. return 0;
  43.  
  44. } // end int main()
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/dmd2/src/phobos/std/stdio.d(578): Error: tuple index 0 exceeds 0
/usr/lib/dmd2/src/phobos/std/stdio.d(578): Error: static assert  (isSomeString!(int)) is not evaluatable at compile time
/usr/lib/dmd2/src/phobos/std/stdio.d(580): Error: template std.format.formattedWrite(Writer,F,A...) does not match any function template declaration
/usr/lib/dmd2/src/phobos/std/stdio.d(580): Error: template std.format.formattedWrite(Writer,F,A...) cannot deduce template function from argument types !()(LockingTextWriter)
stdout
Standard output is empty