Control Flow

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 6.0


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 4th Dimension language contains statements that control each of these structures.

Sequential structure

The sequential structure is a simple, linear structure. A sequence is a series of statements that 4th Dimension 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)

Branching structures

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.

Looping structures

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:

While...End while

Repeat...Until

For...End for

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: 4th Dimension allows you to embed programming structures (If/While/For/Case of/Repeat) up to a "depth" of 512 levels.

See Also

Logical Operators, Methods.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next