Pseudocode Guidelines
• The keywords used for pseudocode in this document
are:
for start and finish
BEGIN MAINPROGRAM, END MAINPROGRAM
for initialisation
INITIALISATION, END INITIALISATION
for subprogram
BEGIN SUBPROGRAM, END SUBPROGRAM
for selection
IF, THEN, ELSE, ENDIF
for multi-way selection
CASEWHERE, OTHERWISE, ENDCASE
for pre-test repetition
WHILE, ENDWHILE
for post-test repetition
REPEAT, UNTIL
SamD said:For...Next loops are referred to in the SDD Prelim course, and in the SDD Course Specifications. The course specifications use FOR...ENDFOR but the syllabus says FOR...NEXT. I've covered them in my Prelim text and have said either syntax is OK.
As a consequence it should be OK to use them when writing Pseudocode, however they should be avoided on flowcharts.
HTH
Sam
this document was put out after the new course, but as i said, the specs are the sameJ0n said:I didn't know there was a new "methods of algorithm description" document - where do we find that??
Oh cool, thanksraymes said:this document was put out after the new course, but as i said, the specs are the same
http://www.boardofstudies.nsw.edu.au/syllabus_hsc/pdf_doc/softwaredesign_specs.pdf
Why wouldn't you use FOR...NEXT loops? - do you mean just to be safe for the HSC, or is there actually some other reason not to use them?SamD said:But personally I'd avoid FOR...NEXT loops altogether when writing algorithms.
And many compilers will dereference it after the loop has completed it any case. Some even make it illegal to refer to a counted loop variable outside the counted loop.SamD said:What is the value of Count once the loop FOR Count=1 TO 10 completes? Is it 10 or is it 11? I think in most programming languages it would be 10, but I may be wrong! And what should it be in psuedocode? Who knows! Hence it's dangerous to use the value of the loop counter after the iterations finish.
indeed, but this isn't really a practical concern seeing as most environments provide standard break/exit loop (and continue/skip) functions. There's no reason not to really when the whole thing just breaks down to JMP (x86) codes in the end. But I agree in BOS pseudocode there is no real way to terminate a counted loop.You can't get out of a FOR...NEXT loop as elegantly as you can from a WHILE loop. You can reset the loop counter within the loop but that seems a bit bodgy to me.
Tip to students: whenever writing these silly algorithms, do them double spaced so when you work out you've chosen the wrong loop type can can cross it out!You can't add an extra condition. For example you can't have FOR X=1 TO 10 OR End of File. This makes it difficult if you realise half way through answering a question that you'd like to get out the loop under certain circumstances.
This is true but they are also the most commonly used loop statement in programming. You'd almost expect them in BOS pseudo-Pascal pseudocode...FOR...NEXT loops are a particular implementation of Pretest loops. So why not just explain the full logic using a WHILE structure. The amount of extra work is pretty trivial.
Despite this, I am still suggesting students avoid using them. As Winston says, they are just WHILE loops with a initialiser and incrementer.HTH
Sam