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.

Advertisements

D Programming – Loops(For Loop)

Most of the time, students get confused of the usage of looping. I always say, “Imagine a block of code that prints 10 consecutive numbers. One way of doing it is by printing them one-by-one. That would be easy if printing 10 numbers is the case but if your program needs to print 1000 numbers then that would be a very long program just for printing. The answer to that problem is looping. If you use a loop, you just define a starting point, a condition of where you are going to stop, and the process if it is increasing or decreasing. A block of 1000 codes would just take three to four lines of codes.”

 

In this program we are going to use a loop called a for loop. I used a variable x to hold the value that will be printed then I declared the starting value and ending value which are inside the range.

Below is my program.

import std.stdio;

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

 

Here is my output:

d-for

 

Thank you for reading this short post. 🙂

Don’t foget to leave a comment.

Python – Loops(While Loop)

This article is a continuation of this last post:
https://arjunaraneta.wordpress.com/2014/08/26/python-loopsfor-loop/

The difference is I used a while in this program. The syntax of the for and while loops and different in terms of the codes used but the concept of a block with a starting value, ending value, and a process of increase and decrease are the same.

 

Here is my code.

loop3

 

Your output should be the same as below:
loop2

 

Thank you for reading this post.

Python – Loops(For Loop)

Most of the time, students get confused of the usage of looping. I always say, “Imagine a block of code that prints 10 consecutive numbers. One way of doing it is by printing them one-by-one. That would be easy if printing 10 numbers is the case but if your program needs to print 1000 numbers then that would be a very long program just for printing. The answer to that problem is looping. If you use a loop, you just define a starting point, a condition of where you are going to stop, and the process if it is increasing or decreasing. A block of 1000 codes would just take three to four lines of codes.”

 

In this program we are going to use a loop called a for loop. I used a variable x to hold the value that will be printed then I declared the starting value and ending value which are inside the range.

Below is my program.

loop1

 

Here is my output:

loop2

 

Thank you for reading this post. 🙂