Nested Control Constructs
You can put control constructs in other control constructs.
You can put a decision construct, for example,
If…Else, in a loop construct, for example,
These control constructs are nested.
You can nest control constructs without limit. To make code easier to read, we recommend that you indent each new level.
If you indent the body of each control construct, you help make your code easy to read and maintain. But, if you cannot see all your indented code on the screen, this can be an indication that you nested it too much.
The example that follows is a method to multiply two 3×3 matrixes.
Method Multiply(result(), a(), b() As Real64*2) Var i, j, k As Int32 For i = 0 To 2 For j = 0 To 2 result(i, j) = 0 For k = 0 To 2 result(i, j) += a(i, k) * b(k, j) End For k End For j End For i End Method
Nesting different types of control constructs
Overlap of control constructs
You cannot have overlap of part of one control construct with a different one. Each control construct must nest fully in the other. If you do not, the result is a compile-time error.