DOORS DXL Tutorial – Part 5

DXL Tutorial

In this series of articles, I am going to explain to you about IBM DOORS DXL scripting from scratch. So, if you are a beginner in DXL scripting, hopefully, this article would help you. This is the 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.

If-else condition in DXL

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 condition. Therefore, we can avoid the curly braces. However, 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-elseif-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 loop available in DXL:

  1. Traditional C-like For loop
  2. For loop with 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 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 loop in DXL

Here is the syntax of 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 three different types of loop control mechanism 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 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. Break statement breaks the loop and starts executing rest of the program, whereas 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 the 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, I will discuss about the strings and how to use string in DXL.

DOORS DXL Tutorial – Part 5

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top
error: