********** >* Using the FLOWER block with the FLYAWAY instruction >***** > 01: FLOWER > 02: SELECT myTable > 03: SCAN > 04: FOR lnI = 1 TO 10 > 05: IF someTestOnThisData(lnI) > 06: WAIT WINDOW "It was found!" > 07: FLYAWAY > 08: ENDIF > 09: NEXT > 10: ENDSCAN > 11: WAIT WINDOW "Sorry, Charlie!" > 12: ENDFLOWER > 13: * Control continues beyond here > ----- > Assuming going through the FOR loop twice, 12 steps: > 01, 02, 03, 04, 05, 08, 09, 04, 05, 06, 07, 13 > > * 12 steps, and the functional code (the "WAIT WINDOW" commands) is > * nested inside the program and must be sought after. > > >********** >* The correct STRUCTURED PROGRAMMING code is... >***** > 01: llFound = .F. > 02: SELECT myTable > 03: GO TOP > 04: DO WHILE (A) NOT EOF() AND (B) NOT llFound > 05: lnI = 1 > 06: DO WHILE NOT (A) llFound AND (B) lnI <= 10 > 07: IF someTestOnThisData(lnI) > 08: WAIT WINDOW "It was found!" NOWAIT > 09: llFound = .T. > 10: ENDIF > 11: lnI = lnI+1 > 12: ENDDO > 13: IF NOT llFound THEN > 14: SKIP > 15: ENDIF > 16: ENDDO > 17: IF NOT llFound > 18: WAIT WINDOW "Sorry, Charlie!" > 19: ENDIF > 20: * Control continues beyond here > ----- > Assuming going through the FOR loop twice, 29 steps: > 01, 02, 03, 04a, 04b, 05, 06a, 06b, 07, 10, 11, 12, 06a, 06b, 07, 08, 09, 10, 11, 12, 06a, 13, 15, 16, 04a, 04b, 17, 19, 20 > > * And also the functional code is nested inside the program and must > * be sought after. > > >********** >* Extending the FLOWER block to use PETALs and the FLYTO instruction: >***** > 01: FLOWER > 02: SELECT myTable > 03: SCAN > 04: FOR lnI = 1 TO 10 > 05: IF someTestOnThisData(lnI) > 06: FLYTO foundIt > 07: ENDIF > 08: NEXT > 09: ENDSCAN > 10: FLYTO notFound > 11: > 12: > 13: PETAL foundIt > 14: WAIT WINDOW "It was found!" > 15: > 16: PETAL notFound > 17: WAIT WINDOW "Sorry, Charlie!" > 18: > 19: ENDFLOWER > 20: * Control continues beyond here > ----- > Assuming going through the FOR loop twice, 12 steps: > 01, 02, 03, 04, 05, 07, 08, 04, 05, 06, 14, 20 > > * This style has the advantage of moving the code related to logic conditions > * outside of the nested areas they would otherwise appear, simultaneously documenting > * (as per the use of the "foundIt" and "notFound" names) what operation takes place > * there, while also documenting the explicit operations at the end of the FLOWER. > * This creates a way to provide more easy to follow logical flow to a program, while > * doing a better job of automatically documenting it. >>