Talk:Loops/N plus one half: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with 'I noticed that many implementations don't run the loop 9.5 times. Instead a check is made whether the comma has to be printed. This way the loop still runs exactly 10 times, with…')
 
No edit summary
Line 1: Line 1:
I noticed that many implementations don't run the loop 9.5 times. Instead a check is made whether the comma has to be printed. This way the loop still runs exactly 10 times, with a different action taken depending on the loop variable.
I noticed that many implementations don't run the loop 9.5 times. Instead a check is made whether the comma has to be printed. This way the loop still runs exactly 10 times, with a different action taken depending on the loop variable.
:This is pointed out in the description:
in the last iteration one executes only part of the loop body
:Notice the quotes around n+1/2 showing that it's not literally n+1/2 times, but rather the last time through only part of the work is done. Running the loop 9.5 times isn't a requirement, but if you can get your language to do it then go for it. --[[User:Mwn3d|Mwn3d]] 21:09, 4 November 2009 (UTC)

Revision as of 21:09, 4 November 2009

I noticed that many implementations don't run the loop 9.5 times. Instead a check is made whether the comma has to be printed. This way the loop still runs exactly 10 times, with a different action taken depending on the loop variable.

This is pointed out in the description:
in the last iteration one executes only part of the loop body
Notice the quotes around n+1/2 showing that it's not literally n+1/2 times, but rather the last time through only part of the work is done. Running the loop 9.5 times isn't a requirement, but if you can get your language to do it then go for it. --Mwn3d 21:09, 4 November 2009 (UTC)