Anonymous user
Stair-climbing puzzle: Difference between revisions
→{{header|C}}: Adapted C++ version into something that will work with classic K&R too
m (→{{header|C++}}: whitespace) |
(→{{header|C}}: Adapted C++ version into something that will work with classic K&R too) |
||
Line 58:
=={{header|C}}==
<lang c>void step_up()
{
while (!step()) {
step_up();
}
}</lang>
The following uses a variable and is a bit longer, but avoids a possible stack overflow:
<lang c>void step_up()
{
int i = 0;
while (i < 1) {
if (step()) {
++i;
} else {
--i;
}
}
}</lang>
=={{header|C++}}==
|