Home

hersto:  Source Code Indentation / Nested Loops

 

Rant to the author:

    

Check for a response

Please read Source Code Indentation for the basic idea first.

Some programming languages support naming a loop and the statements controlling the loop execution can reference a specific loop. In this case the indentation of the statements reflects the loop they reference.

An Example:

 1:  lFiles: for my $FileName ($aFileNames)
 2:  {
 3:      my $File= fopen($FileName, 'r');
 4:
 5:      if(!$File)
 6:  next lFiles;
 7:
 8:      my $Result= '';
 9:
10:      lLines: while(my $Line= ReadLine($File))
11:      {
12:          if($Line == '')
13:      next lLines;
14:
15:          my $Ret= ProcessLine($Line, $Result);
16:
17:          if($Ret == 'eof')
18:      last lLines;
19:
20:          if($Ret == 'abort')
21:  next lFiles;
22:      }
23:
24:      ProcessResult($Result, $FileName);
25:  }

Here the next and last statements are indented so that they make clear which loop they influence.

 

__.-.__
end of document