Il 20/06/2023 09:05, Hairy Pixels via fpc-pascal ha scritto:

Educators continuously have stupid ideas that don't work out as intended in the 
real world.  I would love to see them make a real program that does something 
difficult and not use early breaks.

I assume them they forbid early exits in functions also or is the loop special 
for them?

You don't need something difficult to show that avoiding break is stupid!
Just take a loop searching a linked list for a specific item. You must test two conditions: item found or end of list. But the item you're searching might be the last one, so you can't test next=Nil at the beginning of a do-while loop. A repeat-until can't be used because the list might be empty.

I prefer in those cases use a function, and exit instead of break, so that the caller can easily test how the loop was terminated, but it's just a matter of tastes.

Giuliano

--
Do not do to others as you would have them do to you.They might have different 
tastes.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to