DOORS DXL Tutorial

DOORS DXL Tutorial Part 5

In this series of articles, I am going to explain to you DOORS DXL – If else condition. So, if you are a beginner in DXL scripting, hopefully, this article will help you. This is part-5 of the DOORS DXL tutorial.

So, if you are looking for a starting point to learn DXL scripting, you are on the right page! I know, we have the DXL reference manual and it’s a bit concise and difficult to grasp for beginners, especially if you do not have any previous experience in other programming languages.

In this article, we will mainly discuss the flow control in DXL.

DOORS DXL – If else condition

You can execute a set of statements based on certain conditions. We can implement such logic using the if condition in DXL.

Here is the structure of the if-else condition in DXL:

if (condition true)
Statement-1
else
Statement-2

We have only one statement to execute under if and else conditions. Therefore, we can avoid curly braces. However, if you have multiple statements to execute under the condition, then you need to use curly braces after the if condition. Here is another structure of the if-else condition:

if (condition true) {
Statement-1
Statement-2
}
else {
Statement-3
Statement-4
}

There is another if-else if-else structure you can use in DXL:

if (condition true) {
Statement-1
Statement-2
}
else if (condition true) {
Statement-3
Statement-4
}
else {
Statement-3
Statement-4
}

Now, since we know the structure of the if-else condition in DXL, let us now take a look at an example DXL script:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.1.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

//if-else condition example
int i = 50, j = 60;
if(i<j){
	print("i is less than j.");
}
else{
	print("i is NOT less than j.");
}

For Loop in DXL

There are three different types of for loops available in DXL:

  1. Traditional C-like For loop
  2. For loop with a range of values
  3. For loop for DOORS collection

Traditional For Loop in DXL

Here is the syntax of the traditional for loop:

for (<initial statement>; <repeat condition>; <increment>) {
……………………
……………………
}

Here is an example of the for loop:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.2.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

//For loop example
int i = 0, sum = 0;

for(i=0;i<5;i++){
	sum = sum + i;
}

print("Sum is = " sum "");

For loop with a range of values

There is another type of for loop that is available in DXL. This is a bit different than the traditional for loop:

for <index> in <range> by <step> do {
………………………..
………………………..
}

Here is an example script:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.3.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

//For loop example
int i = 0, sum = 0;

for i in 0:5 by 1 do{
	sum = sum + i;
}

print("Sum is = " sum "");

For loop for DOORS collection

This type of for loop is mainly used for DOORS collection. Here is the syntax:

for <&var> in <collection> do {
……………………
……………………
}

Here is an example script:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.4.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

//For loop example
int i = 0, fact = 1;

for i in 0:5 by 1 do{
	fact = fact * i;
}

print("Fact is = " fact "");

While looping in DXL

Here is the syntax of the while loop in DXL:

while ( condition true ) {
statements
}


Here is an example script:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.5.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

//while loop example
int i = 0, sum = 0;

while(i<=5){
	sum = sum + i;
        i++;
}

print("Sum is = " sum "");

Loop Control in DXL

There are three different types of loop control mechanisms in DXL.

  1. break – jumps out of the loop immediately
  2. continue – jumps to the starting of the loop without executing the statements after the continue statement
  3. halt – terminates the execution of the script

Here is an example script to demonstrate the break statement in the context of a while loop:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.6.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

// break
int i = 0, sum = 0;

while(i<10){
	sum = sum + i;
	i++;
	if(i>7)
		break;
}

print("Sum is = " sum "");

Now, let us look into continue statement:

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.7.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

// continue
int i = 0, sum = 0;

while(i<10){
	sum = sum + i;
	i++;
	if(i<5)
		continue;
}

print("Sum is = " sum "");

Here is another example of Halt. There is a small difference between break and halt. The break statement breaks the loop and starts executing the rest of the program, whereas the halt statement halts the program immediately; no statement will execute after the halt statement.

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d5.8.dxl
* $DESCRIPTION: This is a sample DXL program.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

// continue
int i = 0, sum = 0;

while(i<10){
	sum = sum + i;
	i++;
	if(i==7) {
		print("Halt when i is : " i "");
		halt;
	}
}

print("Sum is = " sum "");

Conclusion

This was part-5 of the DOORS DXL tutorial. The intention of this article was just to familiarize you with DOORS DXL and show you different data types that are supported by DXL scripting. Please comment below if you have any questions/suggestions.

In the next DOORS DXL tutorial, we will discuss the strings and how to use strings in DXL.

DOORS DXL – If else condition
Scroll to top
error: Content is protected !!