WHILE .. DO Loop

WHILE .. DO Loop or Statement In Microsoft Dynamics NAV C/AL

Definition

The WHILE .. DO Loop is a repetitive statement or loop, is used in the program where a certain code is to be executed as long as some condition is true.

Syntax Of WHILE .. DO Loop

-----------------------------------------------------

WHILE Boolean Expression DO Statement

-----------------------------------------------------

This is simpler than the IF loop. In the case of  WHILE .. DO Loop the system check continously the boolean expression become true then the statement between BEGIN and END execute otherwise move to next statement.

For Example:

==================================================

WHILE Sales[i+1] <> 0 DO BEGIN

     i := i + 1;

     Total Sales :=  Total Sales + Sales[i];

END;

==================================================

This is work in a manner like that check every time the Sales[i+1] <> 0 and if the condition is true then execute the statement between BEGIN and END other wise execute after the END statement.

Related Posts with Thumbnails