4D v13.4

Control Flow

Home

 
4D v13.4
Control Flow

Control Flow  


 

 

Regardless of the simplicity or complexity of a method, you will always use one or more of three types of programming structures. Programming structures control the flow of execution, whether and in what order statements are executed within a method. There are three types of structures:

  • Sequential
  • Branching
  • Looping

The 4D language contains statements that control each of these structures.

The sequential structure is a simple, linear structure. A sequence is a series of statements that 4D executes one after the other, from first to last. For example:

 OUTPUT FORM([People];"Listing")
 ALL RECORDS([People])
 DISPLAY SELECTION([People])

A one-line routine, frequently used for object methods, is the simplest case of a sequential structure. For example:

 [People]Last Name:=Uppercase([People]Last Name)

Note: The Begin SQL / End SQL keywords can be used to delimit sequential structures to be executed by the SQL engine of 4D. For more information, please refer to the description of these keywords.

A branching structure allows methods to test a condition and take alternative paths, depending on the result. The condition is a Boolean expression, an expression that evaluates TRUE or FALSE. One branching structure is the If...Else...End if structure, which directs program flow along one of two paths. The other branching structure is the Case of...Else...End case structure, which directs program flow to one of many paths.

When writing methods, it is very common to find that you need a sequence of statements to repeat a number of times. To deal with this need, the language provides three looping structures:

The loops are controlled in two ways: either they loop until a condition is met, or they loop a specified number of times. Each looping structure can be used in either way, but While loops and Repeat loops are more appropriate for repeating until a condition is met, and For loops are more appropriate for looping a specified number of times.

Note: 4D allows you to embed programming structures (If/While/For/Case of/Repeat) up to a "depth" of 512 levels.

 
PROPERTIES 

Product: 4D
Theme: Language definition

 
SEE ALSO 

Logical Operators
Methods