Selection Structures
Previous  Top  Next


These structures allow to check a certain condition to execute some operations.
 
1."if" EXPR "then" BLOCK |  
2."if" EXPR "then" BLOCK "else" BLOCK |  


INSTR = "if" EXPR "then" BLOCK |

-Example 1:  
// If existent it is true then deletes file
If Esistente= True Then DeleteFile(File);

-Example 2:  
// 
If existent it is true then … 
If Esistente=True Then  
 Begin

//…It deletes file  
DeleteFile(File);  
 
//…It creates a directory  
CreateDir ('c:\files');  
 
//…It creates a file  
CreateFile(File);  
 End;

INSTR = "if" EXPR "then" BLOCK "else" BLOCK |

-Example 1:  
// 
If existent it is true then deletes file…
If Esistente= True Then DeleteFile(File);
 
//…otherwise create file  
Else CreateFile(File);  
-Example 2:  
// 
If existent it is true then … 
If Esistente=True Then  

//It deletes file
DeleteFile(File);  
 
//…otherwise…  
Else   
Begin  
//…It creates a directory  
CreateDir ('c:\files');  
 
//…It creates a file  
CreateFile(File);  
End;