Talk:Loops/Do-while: Difference between revisions

From Rosetta Code
Content added Content deleted
(Possible rewording.)
Line 3: Line 3:
If value is supposed to start at "zero" and looping is to be performed "while value mod 6 is not equal to zero", then it follows that the loops should be executed zero times since 0 mod 6 == 0. Requiring that the loop should execute at least once is in conflict with the other requirements.[[User:Sgeier|Sgeier]] 04:54, 15 September 2009 (UTC)
If value is supposed to start at "zero" and looping is to be performed "while value mod 6 is not equal to zero", then it follows that the loops should be executed zero times since 0 mod 6 == 0. Requiring that the loop should execute at least once is in conflict with the other requirements.[[User:Sgeier|Sgeier]] 04:54, 15 September 2009 (UTC)
: I believe the goal is to demonstrate a post-execute condition check, but I don't have a good idea of precise-yet-clear ways to describe it, and that interpretation of the behavior is specific to imperative programming. "Process at least once, or while condition is true" might be closer. --[[User:Short Circuit|Michael Mol]] 06:31, 15 September 2009 (UTC)
: I believe the goal is to demonstrate a post-execute condition check, but I don't have a good idea of precise-yet-clear ways to describe it, and that interpretation of the behavior is specific to imperative programming. "Process at least once, or while condition is true" might be closer. --[[User:Short Circuit|Michael Mol]] 06:31, 15 September 2009 (UTC)

: <cite>Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it.</cite> It is not clear (maybe the title do-while should suggest that, at least to C-or-similar coders), but the condition is tested at the end of the loop, so that the value has get incremented already (<cite>each time through the loop ad 1 to the value</cite>). Anyway the final <cite>The loop must execute at least once</cite> can be read as: (if needed) fix it so that the loop is executed at least once. --[[User:ShinTakezou|ShinTakezou]] 09:18, 15 September 2009 (UTC)

Revision as of 09:18, 15 September 2009

self-contradictory task?

If value is supposed to start at "zero" and looping is to be performed "while value mod 6 is not equal to zero", then it follows that the loops should be executed zero times since 0 mod 6 == 0. Requiring that the loop should execute at least once is in conflict with the other requirements.Sgeier 04:54, 15 September 2009 (UTC)

I believe the goal is to demonstrate a post-execute condition check, but I don't have a good idea of precise-yet-clear ways to describe it, and that interpretation of the behavior is specific to imperative programming. "Process at least once, or while condition is true" might be closer. --Michael Mol 06:31, 15 September 2009 (UTC)
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. It is not clear (maybe the title do-while should suggest that, at least to C-or-similar coders), but the condition is tested at the end of the loop, so that the value has get incremented already (each time through the loop ad 1 to the value). Anyway the final The loop must execute at least once can be read as: (if needed) fix it so that the loop is executed at least once. --ShinTakezou 09:18, 15 September 2009 (UTC)