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 NestedFunctionsExample/D1

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

--

Legend:

Unmodified
Added
Removed
Modified
  • NestedFunctionsExample/D1

    v0 v1  
     1= Nested Functions = 
     2 
     3''Part of'' TutorialFundamentals 
     4 
     5== Description == 
     6 
     7Nested functions allows you to structure functions in a clever way if that's how your mind works. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13import std.stdio; 
     14 
     15int main(char[][] Args) { 
     16  int i; 
     17 
     18  void runIt() { 
     19    /* This is a nested function. You can make use of variables declared in the outer 
     20       function, but each has to be declared above the location of the nested function 
     21       if you use it.*/ 
     22 
     23    writef("%d\tdo something\t", i); 
     24  } 
     25 
     26  bool found; 
     27  while (!found) { 
     28    if(i == 0) { 
     29        writef("not found\t"); 
     30        runIt(); 
     31        return 0; 
     32    } 
     33    found = true; 
     34  } 
     35  return 0; 
     36} 
     37}}} 
     38 
     39== Testing == 
     40 
     41Tested using Digital Mars D Compiler v1.026 on Windows 2000.  
     42 
     43 
     44== More Information == 
     45 
     46See also the [http://www.digitalmars.com/d/1.0/function.html#nested D Specification].