0

This is a question for program design. There are 2 possibilities I see, where I want to know which one is better and why (aspects: readability, performance, expendability, complexity etc.) If you got an other one (sequential only pls no OO stuff xD) feel free to post it and explain its pros and cons

It is a simple report looping over entries from a file, doing something with them and generate a printfile (without a dedicated printer, 3rdparty software, I need to calculate the pages by myself)

Solution NESTED LOOPS in pseudocode

//loop over entries
perform until End-Of-File

  perform page-heading    
  //loop over pages
  perform until End-Of-File or End-Of-Page

    perform calculate-entry
    perform print-entry

  end-perform
  perform page-footer
end-perform

Solution EVENT in pseudocode

//loop over entries
perform until End-Of-File

  evaluate line-counter
    case heading-position
      perform page-heading
    case footer-position
      perform reset-line-counter
      perform page-footer
    case other
      perform calculate-entry
      perform print-entry
  end-evaluate
end-perform

My final program will be in cobol, but I occurred the same question in ABAP so feel free to argument with any sequential language.

inetphantom
  • 2,498
  • 4
  • 38
  • 61
  • 1
    I'm extremely tempted to down vote this simply for the dismissal of state-of-the-art technology and methodology... – vwegert Jun 03 '17 at 11:25

1 Answers1

3

The first one (nested loops) is the more traditional way, and I prefer it, as I was a COBOL programmer last century:) However, you should probably look at the preferred coding style in your organisation in order to decide. If you are interested in the performance question, here is a similar question, about if vs evaluate, rather than nested loops, but there is a long and very interesting answer. Which is better in terms of performance? "if else" or "Evaluate" statement in COBOL?

Lizi
  • 43
  • 7