Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of ForLoopExample/D2

Show
Ignore:
Author:
Andrej08 (IP: 93.137.24.64)
Timestamp:
09/04/10 20:03:45 (14 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ForLoopExample/D2

    v0 v1  
     1= The ''for'' Loop = 
     2 
     3''Part of'' TutorialFundamentals 
     4 
     5== Description == 
     6 
     7How to do the same thing over and over again. 
     8 
     9== Example == 
     10 
     11Most people don't like to do monotonous tasks over and over again (especially not a lazy programmer). That's where the '''for''' loop comes in. You could write a program like this: 
     12{{{ 
     13    write("1\n"); 
     14    write("2\n"); 
     15    write("3\n"); 
     16    write("4\n"); 
     17    ... 
     18}}} 
     19but that's no fun. The '''for''' statement allows the programmer step back and just say to the computer, "count from 1 to 10, and print each number." 
     20 
     21==== Example Code ==== 
     22{{{ 
     23#!d 
     24import std.stdio; 
     25 
     26void main()  
     27{ 
     28    for (int i = 1; i <= 10; i++) 
     29        writeln(i); 
     30} 
     31}}} 
     32 
     33== Output == 
     34 
     35{{{ 
     361 
     372 
     383 
     394 
     405 
     416 
     427 
     438 
     449 
     4510 
     46}}} 
     47 
     48== Source == 
     49 
     50Partially based on: [http://jcc_7.tripod.com/d/tutor/for_loop.html The for Statement]