Using do-while Loops in X++: Syntax and Examples

Rumman Ansari   Software Engineer   2024-10-19 12:53:22   7234  Share
Subject Syllabus DetailsSubject Details Login to Open Video
☰ TContent
☰Fullscreen

Table of Content:


Syntax


do {
   // Loop body;
   Statement(s);
} while (loop-continuation-condition);


Flow Chart

Do While Loop Flowchart
Figure: Do While Loop Flowchart


Example

The given code is an example of a do-while loop in X++ programming language. It declares an integer variable n and initializes it to 0.

The do-while loop in X++ is a loop statement that executes a block of statements repeatedly until the specified condition becomes false. In this case, the loop block contains a call to the info function which prints the value of n along with the string "Number " to the infolog.

In each iteration of the loop, the value of n is incremented by 1 until it reaches 10. Once n becomes equal to or greater than 10, the condition n < 10 becomes false and the loop terminates.

Therefore, this code will print the numbers from 0 to 9 to the infolog window.


// do while loop example

static void Examples(Args _args)
{ 
	int n = 0;

	do{
			info(strFmt("Number %1",n));
			n++;
	} while(n < 10);
}


MCQ Available

There are 3 MCQs available for this topic.

3 MCQ