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

Changes between Version 1 and Version 2 of ReturnExample

Show
Ignore:
Author:
csauls (IP: 69.166.134.113)
Timestamp:
01/23/06 08:48:24 (18 years ago)
Comment:

Updated to use writef, and other miscellany.

Legend:

Unmodified
Added
Removed
Modified
  • ReturnExample

    v1 v2  
    1111{{{ 
    1212#!d 
    13 /*  
    14     Return exits a function.  
    15     If it's not a void function return allows you to return a value.  
    16 */ 
     13/* Return exits a function.  
     14 * If it's not a void function return allows you to return a value.  
     15 */ 
    1716 
    18 void f1()  
    19 
    20     printf("Running f1...\n");     
     17import std.stdio; 
     18 
     19void f1 () { 
     20  writefln("Running f1..."); 
    2121} 
    2222 
    23 void f2()  
    24 {  
    25     bit itsAGoodIdea = true; 
     23void f2 () {  
     24  bit itsAGoodIdea = true; 
    2625 
    27     printf("Running f2...\n"); 
     26  writefln("Running f2..."); 
    2827     
    29     if(itsAGoodIdea) 
    30     { 
    31         f1(); 
    32         return;  
    33     } 
    34     printf("Don't go there.\n"); 
     28  if(itsAGoodIdea) { 
     29    f1(); 
     30    return;  
     31  } 
     32 
     33  writefln("Don't go there."); 
    3534} 
    3635 
     36void main () { 
     37  f2(); 
     38  writefln("The end."); 
     39} 
     40}}} 
    3741 
    38  
    39 void main() 
    40 
    41     f2(); 
    42     printf("The end.\n"); 
    43 
    44  
    45 /* 
    46  
    47 Output: 
    48  
     42== Output == 
     43{{{ 
    4944Running f2... 
    5045Running f1... 
    5146The end. 
    52  
    53 */  
    5447}}} 
    55  
    56 == Source == 
    57  
    58 || Link || http://www.dsource.org/tutorials/index.php?show_example=92 || 
    59 || Posted by || jcc7 || 
    60 || Date/Time || Sat May 22, 2004 1:45 pm ||