Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning D

You're reading from   Learning D Leverage the modern convenience and modelling power of the D programming language to develop software with native efficiency

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781783552481
Length 464 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Michael Parker Michael Parker
Author Profile Icon Michael Parker
Michael Parker
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. How to Get a D in Programming 2. Building a Foundation with D Fundamentals FREE CHAPTER 3. Programming Objects the D Way 4. Running Code at Compile Time 5. Generic Programming Made Easy 6. Understanding Ranges 7. Composing Functional Pipelines with Algorithms and Ranges 8. Exploring the Wide World of D 9. Connecting D with C 10. Taking D Online 11. Taking D to the Next Level Index

Control flow statements

D includes the traditional loop and conditional statements found in other C-family languages. It also supports the infamous goto statement. It has a couple of other useful statements, such as a built-in foreach statement and a rather unique scope statement. In this section, we're going to look at examples of each of the first two. Because of their relation with exceptions, scope statements are included in detail in the next chapter.

Traditional loops

In terms of looping constructs, we have for, do, and do-while. The syntax and behavior should be familiar. Here is an example of each iterating over an array:

auto items = [10,20,30,40,50];
for(int i=0; i<items.length; ++i)
  writeln(items[i]);

int i = 0;
while(i < items.length)
  writeln(items[i++]);

i = 0;
do {
  writeln(items[i++]);
} while(i < items.length);

No surprises there. The braces are optional with for and while when they only contain one statement. When a loop with an empty body is desired, the...

You have been reading a chapter from
Learning D
Published in: Nov 2015
Publisher:
ISBN-13: 9781783552481
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image