Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import std.stdio;
int main () {
/* local variable definition */
int a = 100;
/* check the boolean condition */
if( a < 20 ) {
/* if condition is true then print the following */
writefln("a is less than 20" );
} else {
/* if condition is false then print the following */
writefln("a is not less than 20" );
}
writefln("value of a is : %d", a);
return 0;
}
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* check the boolean condition using if statement */
if( a < 20 ) {
/* if condition is true then print the following */
writefln("a is less than 20" );
}
writefln("value of a is : %d", a);
return 0;
}
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* do loop execution */
do {
if( a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}
writefln("value of a: %d", a);
a++;
} while( a < 20 );
return 0;
}
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 ) {
writefln("value of a: %d", a);
a++;
if( a > 15) {
/* terminate the loop using break statement */
break;
}
}
return 0;
}
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* do loop execution */
do{
writefln("value of a: %d", a);
a = a + 1;
}while( a < 20 );
return 0;
}
import std.stdio;
int main () {
/* local variable definition */
int a = 10;
/* while loop execution */
while( a < 20 ) {
writefln("value of a: %d", a);
a++;
}
return 0;
}
import std.stdio;
int main(string[] args) {
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = (a + b) * c / d; // ( 30 * 15 ) / 5
writefln("Value of (a + b) * c / d is : %d\n", e );
e = ((a + b) * c) / d; // (30 * 15 ) / 5
writefln("Value of ((a + b) * c) / d is : %d\n" , e );
e = (a + b) * (c / d); // (30) * (15/5)
writefln("Value of (a + b) * (c / d) is : %d\n", e );
e = a + (b * c) / d; // 20 + (150/5)
writefln("Value of a + (b * c) / d is : %d\n" , e );
return 0;
}
import std.stdio;
int main(string[] args) {
int a = 4;
short b;
double c;
int* ptr;
/* example of sizeof operator */
writefln("Line 1 - Size of variable a = %d\n", a.sizeof );
writefln("Line 2 - Size of variable b = %d\n", b.sizeof );
writefln("Line 3 - Size of variable c= %d\n", c.sizeof );
/* example of & and * operators */
ptr = &a; /* 'ptr' now contains the address of 'a'*/
writefln("value of a is %d\n", a);
writefln("*ptr is %d.\n", *ptr);
/* example of ternary operator */
a = 10;
b = (a == 1) ? 20: 30;
writefln( "Value of b is %d\n", b );
b = (a == 10) ? 20: 30;
writefln( "Value of b is %d\n", b );
return 0;
}