Electron microscopy
 
Nested Loops in DM
- Practical Electron Microscopy and Database -
- An Online Book -
Microanalysis | EM Book                                                                                   http://www.globalsino.com/EM/        


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

 

In DM scripts, o ne loop can be nested inside of another. Such a C++ program allows at least 256 levels of nesting. Nested loops are used to solve a wide variety of programming problems, for instance, listed in Table 1131.

Table 1131. Examples of nested loops in DM.

Script
Result from script execution
number EMi, EMj;
for(EMi=2; EMi<1000; EMi++)
{
for(EMj=2; EMj <= (EMi/EMj); EMj++)
if(!(EMi%EMj)) break; // if factor found, not prime
if(EMj > (EMi/EMj))
result ("The EMi" + "\t" + EMi + "\t" + "is a prime number\n")
}
Script code
Print all prime numbers less than 1000

 

 

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