D Programming – Arrays

One of the concepts I love is arrays. I really like putting values inside one container. Feels like cheating and magic at the same time. It can store values and even variables, it can also be one-dimensional or multi-dimensional, and it just solves many problems.

Below is the code for declaring and accessing arrays:

import std.stdio;

int main(){
	int numbers[4] = [5,1,3,10];
	int sum = 0;
	
	for(int i = 0; i<numbers.length; i++){
		sum+= numbers[i];
	}
	
	writeln("The sum is ", sum);
	
	return 0;
}

Here is the output:

 

d-arrays

 

I hope you like this post.

Don’t forget to leave a comment.

Thank you very much.

D Programming – Input

Good Day, I was to talking to little kid this morning and he was asking me what color is the best. Every time I said a color he always answered “Really? (color)?”
What’s your favorite color? Yellow
Really? Yello?

haha, his expression made his annoying answer funny.

I adapated that kid to my program here showing basic input of string in D language.

Here is my annoying kid asking for colors program:

import std.stdio;
import std.string;

int main(){
	string input = "";
	
	write("What is your favorite color? ");
	input = strip(stdin.readln());
	
	writeln("Really? ", input, "?");
	return 0;
}

Here is the output:

d-input

 

I hope you like this post. Don’t forget to leave a comment.

Thank you very much.

D – Programming (Strings)

In programming, Strings are group of characters and they are not those strands of fiber that we tie knots or tie somebody’s neck. I often introduce students to this concept by making them count the letters of their name and resite them in reverse. Quite really fun at times. 🙂

Below is a code that shows string initialization and concatenation:

import std.stdio;

int main(){
	string fname = "Mark";
	string lname = "Hay";
	
	writeln("Hello ", fname, " ", lname);
	
	return 0;
}

Here is the output:

d-strings

 

Don’t forget to leave a comment below.

Thank you very much.

D Programming – While Loop

Hello there, below is a program that show a basic while loop. It is very much like the syntax of C++ and Java. It is really good to remember the parts of a loop like the starting value, end statement and the operation of increment or decrement. Enjoy! 🙂

import std.stdio;

int main(){
	int i = 0;
	
	while(i<11){
		writeln(i);
		i++;
	}
	
	return 0;
}

Here is the output:

d-while

 

Don’t forget to leave a comment below.

Thank you very much.

D Programming – If Statement

Most of the time, every programmer has the need to compare on or two values of variables in your program. Same as most of the programming languages, Python also has its syntax for the If Statement. In this article, I created a program that uses an if statement after the variables x, and y are declared. I assigned values 10 and 5 to variables x and y respectively.

The program is below:

import std.stdio;

int main(){
	int x = 10, y = 5;
	
	if(x > y){
		write("x is greater than y");
	}
	return 0;
}

Your output should be the same as here:
x is greater than y

Thank you for reading this post.

Don’t forget to leave a comment.
 

D Programming – Variables

Hi there, I recently enjoyed learning some programming languages which are new to me. I came across with the D Programming Language. I have already put up an article on the codes on the basic console output in D located here: https://arjunaraneta.wordpress.com/2014/09/27/d-basic-output/

You can think of variables as an address in your memory that contains data that you’ll need and use. The syntax for using variables in python in very straightforward.

Here is a basic example of declaring a variable named x with a value of 10. After declaring and assigning a value, the program will output the value of x.

import std.stdio;

int main(){
int x = 10;
writeln("x = ", x);

  return 0;
}

The output should be:

x = 10

On the next example below, I declared two variables named x and y. I assigned a value for each of the variables. After assigning the values, I created another variable named z assigned the sum of x and y. The program will output the result after the addition.

import std.stdio;

int main(){
	int x = 10, y = 5;
	writeln("x + y = ", x + y);
	
	return 0;
}

The output should be:

x + y = 10

Thank you for your time 🙂
Please leave a comment below.
Be free to ask me questions.

D – Basic Output

In this tutorial, I will be introducing you to a language called D. We will be creating a simple program that outputs “Hello World” on the screen.

First, you should download D here: http://dlang.org/download.html

 

Then, install the software. Installation is very easy because all you need to do is read and follow the directions.

 

After installation, create a new folder in My Documents named tutorials.

While inside the tutorials folder, create a new text document and rename it output.d.

Open the file with your favorite text editor (I love to use Notepad++).

Type the codes same as below:

d1

 

 

Open your command prompt.

Next, change your directory using the cd command.

type dmd then the name of your file

type the name of the exe file that was generated.

our output should be the same as below:

 

d2

 

 

Thank you for reading this post.

Don’t forget to leave a comment.