Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
D (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example 1=== This example program prints its command line arguments. The <code>main</code> function is the entry point of a D program, and <code>args</code> is an array of strings representing the command line arguments. A <code>string</code> in D is an array of characters, represented by <code>immutable(char)[]</code>. <syntaxhighlight lang="D" line highlight="3,5"> import std.stdio: writefln; void main(string[] args) { foreach (i, arg; args) writefln("args[%d] = '%s'", i, arg); } </syntaxhighlight> The <code>foreach</code> statement can iterate over any collection. In this case, it is producing a sequence of indexes (<code>i</code>) and values (<code>arg</code>) from the array <code>args</code>. The index <code>i</code> and the value <code>arg</code> have their types inferred from the type of the array <code>args</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)