ChatterBox

BlitzPlus Forums/BlitzPlus Beginners Area/ChatterBox

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ok, crashcourse on indenting:

Commands like For-Next, Repeat-Until, Select-Case-EndSelect etc. define a certain 'area' in which something happens or gets chosen. This area is usually a number of lines in size, sometimes truly a huge area. This area is called a 'scope'.

For readability, one is suggested to indent a scope so that one can easily see where a scope starts and ends. A lot of bugs can be prevented this way.

So, like this:
For b=0 To 7
  For a=0 To 9
    If a=4
      DebugLog a
      If b=3
        DebugLog b
      Endif
    Endif
  Next
Next


Where 'For a' starts is the scope of the 'For b' instruction, where "Debuglog a" starts is the scope of the "If a=4" instruction.

Put a scope-end command (Next, EndIf, Wend, Until, End Function, End Select etc.) straigt under a scope-start command.

So, to see how that works out in my example:

For b=0 To 7
: For a=0 To 9
: . If a=4
: . : DebugLog a
: . : If b=3
: . : . DebugLog b
: . : Endif
: . Endif
: Next
Next


I suggest using the TAB key for indenting, and a TAB size of 4 characters is kind of a universal standard.

In addition to indenting, also make a habit of placing white lines, also for readability (it won't change the functionality of your program, nor does indenting do so).

For b=0 To 7
  For a=0 To 9

    If a=4
      DebugLog a

      If b=3
        DebugLog b
      Endif

    Endif

  Next
Next


Where and how you add a whiteline is open for debate, try to see certain commands as part of a group. You want to divide groups with whitelines.