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 AssertionsExample/D2

Show
Ignore:
Author:
Andrej08 (IP: 78.2.57.183)
Timestamp:
09/05/10 16:37:43 (14 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AssertionsExample/D2

    v0 v1  
     1= Assertions = 
     2 
     3''Part of'' TutorialFundamentals 
     4 
     5== Description == 
     6 
     7Using assert is a form of testing the code that you write. An assert statement takes an expression as it's first argument, and if that expression evaluates to '''true''', then nothing happens. If however the expression evaluates to false, the statement will raise an '''!AssertError''' and will print out an error message plus an additional string if it's provided as a second argument. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13import std.stdio; 
     14 
     15void main()  
     16{ 
     17    assert(221 % 5 == 1); 
     18    assert(25 * (4 * 20) + 4 == 2004); 
     19     
     20    assert(2 == 4, "2 is not equal to 4!"); 
     21} 
     22}}} 
     23 
     24== More Information == 
     25 
     26More info can be found in the [http://www.digitalmars.com/d/2.0/expression.html#AssertExpression D Specification].