Discussion: Loop Up and Down
Execute the code to understand the output and gain insights into for loops.
We'll cover the following...
Run the code
Now, it's time to execute the code and observe the output.
Press + to interact
#include <stdio.h>int main(){int u,d;for( u=0, d=0; u<11; u++, d-- )printf("%2d %2d\n", u, d);return(0);}
Understanding the output
The code shows the output of both variables u
and d
as they ascend and descend from zero:
0 01 -12 -23 -34 -45 -56 -67 -78 -89 -910 -10
Code output
A single loop both initializes ...