Click here to Skip to main content
15,893,487 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: The Office Desk Move Pin
PIEBALDconsult30-Jul-14 5:28
mvePIEBALDconsult30-Jul-14 5:28 
GeneralRe: The Office Desk Move Pin
Roger16531-Jul-14 2:53
Roger16531-Jul-14 2:53 
GeneralRe: The Office Desk Move Pin
Simon Lee Shugar31-Jul-14 3:17
Simon Lee Shugar31-Jul-14 3:17 
GeneralSSIS Part II Pin
Karen Mitchelle29-Jul-14 23:42
professionalKaren Mitchelle29-Jul-14 23:42 
GeneralRe: SSIS Part II Pin
Shameel30-Jul-14 1:34
professionalShameel30-Jul-14 1:34 
GeneralRe: SSIS Part II Pin
Roger Wright30-Jul-14 11:19
professionalRoger Wright30-Jul-14 11:19 
GeneralRe: SSIS Part II Pin
PIEBALDconsult30-Jul-14 12:41
mvePIEBALDconsult30-Jul-14 12:41 
GeneralLoop exit Pin
kalberts29-Jul-14 23:00
kalberts29-Jul-14 23:00 
Running into a feature-by-feature language comparison made me think back of a feature I saw in one single langugage, but would fit very nicely into a lot of the pascal/c/java/... class of languages: Alternate loop exits.

When iterating through a list, an array or some sort of collection, objects are not all treated equally: You reach a sentinel, find the object you're searching for, reach the capacity of the bucket you are filling up, or whatever. The job has successfully been done, so you exit the loop. Or, you do not complete the job: There is no sentinel (because the buffer is completely filled), the desired object is not found, or the bucket has still some capacitly left.

Running through the collection to the end or not running to the end are different situations, frequently requiring different handling. In most languages, an early exit requires that you set some boolean flag decleared outside the loop, then break (or whatever the keyword is in your favorite language), and after the loop you add an if-statement, syntactically detached from the loop, to provide differnt treatment based on the setting of the flag.

I was programming in this language called Planc - "Programming LANguage for Nord Computers", a vendor specific systems implementation - remmebered by noone today. It had this nice syntactic sugar:
C++
for listpointer in listhead:nextfield do

  ... processing list element as desired

  while listpointer.keyvalue <> desidred_key

  ... porcessing list element as desired

exitwhile
  ... the desired list element was found,
  write("list element was found and processed")

exitfor
  ... reached end of list without finding the desired element
  write("no element with the desired key was found in the list")

endfor

No need for any one-time-use bool cluttering up variable space. No need to introduce a separate block for testing and breaking out. No need for a detached if-statement - the different loop exit handling is syntactically integrated with the loop itself.

I never saw this sort of construct in any other language, but I have been missing it hundred of times. Are there other languages out there with something similar? Certainly not C, C++, Java, C#, Pascal, ...

And, by the way: The above specification of the iteration is a nice syntactic sugar for what would be in C-like languages:
C++
for (listptrtype listpointer = listhead; listpointer != null; listpointer = listpointer->nextfield) {

The Planc syntax is certainly more readable and less error prone, but the two are functionally equivalent.
The exitwhile/exitfor mechanism was valid whether the iteration was over a list, an array or some arbitrary collection, and both were optional: if one (or both) of the loop exits required no special handling, you could leavie that entire clause out.

Gee, I wish I could get that mechanism into, say, C#! The "while" part would be simple: Just add an optional condition after the break ("break (listpointer.keyvalue == desired_key);". Adding exitwhile/exitfor would require two more reserved words, which always causes problems and protests (even though I guess that very few variables out there are named exitwhile or exitfor...).

I once tried to construct C #define macros to emulate it, but never succeeded (if I remember right, the problem was generating jump labels for the gotos). If anyone has tried something similar, give me a hint!
GeneralRe: Loop exit PinPopular
Mark_Wallace29-Jul-14 23:18
Mark_Wallace29-Jul-14 23:18 
GeneralRe: Loop exit PinPopular
Bergholt Stuttley Johnson29-Jul-14 23:26
professionalBergholt Stuttley Johnson29-Jul-14 23:26 
GeneralRe: Loop exit Pin
Mark_Wallace29-Jul-14 23:31
Mark_Wallace29-Jul-14 23:31 
GeneralRe: Loop exit PinPopular
Bergholt Stuttley Johnson29-Jul-14 23:33
professionalBergholt Stuttley Johnson29-Jul-14 23:33 
GeneralRe: Loop exit Pin
Mark_Wallace29-Jul-14 23:38
Mark_Wallace29-Jul-14 23:38 
GeneralRe: Loop exit Pin
CBadger29-Jul-14 23:54
professionalCBadger29-Jul-14 23:54 
GeneralRe: Loop exit Pin
Bergholt Stuttley Johnson30-Jul-14 0:09
professionalBergholt Stuttley Johnson30-Jul-14 0:09 
GeneralRe: Loop exit Pin
Mark_Wallace30-Jul-14 1:08
Mark_Wallace30-Jul-14 1:08 
GeneralRe: Loop exit Pin
Bergholt Stuttley Johnson30-Jul-14 1:46
professionalBergholt Stuttley Johnson30-Jul-14 1:46 
GeneralRe: Loop exit Pin
CBadger30-Jul-14 3:08
professionalCBadger30-Jul-14 3:08 
GeneralRe: Loop exit Pin
Mycroft Holmes30-Jul-14 0:16
professionalMycroft Holmes30-Jul-14 0:16 
GeneralRe: Loop exit Pin
CBadger30-Jul-14 3:09
professionalCBadger30-Jul-14 3:09 
GeneralRe: Loop exit Pin
Mark_Wallace30-Jul-14 1:10
Mark_Wallace30-Jul-14 1:10 
GeneralRe: Loop exit Pin
CBadger30-Jul-14 3:11
professionalCBadger30-Jul-14 3:11 
GeneralRe: Loop exit Pin
WiganLatics30-Jul-14 0:45
professionalWiganLatics30-Jul-14 0:45 
GeneralRe: Loop exit Pin
OriginalGriff29-Jul-14 23:38
mveOriginalGriff29-Jul-14 23:38 
GeneralRe: Loop exit Pin
Mark_Wallace29-Jul-14 23:40
Mark_Wallace29-Jul-14 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.