Practical Electron Microscopy and Database

An Online Book, Second Edition by Dr. Yougui Liao (2006)

Practical Electron Microscopy and Database - An Online Book

Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

Nested Loops in DM

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