Stair-climbing puzzle: Difference between revisions
Content deleted Content added
No edit summary |
→{{header|C++}}: slightly longer version using a variable |
||
Line 9: | Line 9: | ||
{ |
{ |
||
while (!step()) step_up(); |
while (!step()) step_up(); |
||
} |
|||
</lang> |
|||
The following uses a variable and is a bit longer, but avoids a possible stack overflow: |
|||
<lang cpp> |
|||
void step_up() |
|||
{ |
|||
for (int i = 0; i < 1; step()? ++i : --i); |
|||
} |
} |
||
</lang> |
</lang> |