Hardware Reference
In-Depth Information
Figure 7.6 Screen output as it appears in the console window when the
program in Figure 7.5 is executed
#include <stdio.h>
int main()
{
int s;
s=0;
while (s < 4)
{
++s;
printf("Outer loop count = %d\n", s);
inner();
}
return 0;
}
int inner()
{
int t;
t=0;
while (t < 4)
{
++t;
printf("\tInner loop count = %d\n", t);
}
}
The outer loop is executed four times (with s taking the values 0 to 3 in
the expression following while ). The inner loop is executed four times (with t
taking the values 0 to 3 in the expression following while ) on each pass through
the outer loop. The output produced by the program is shown in Figure 7.7.
There are a few things worth noting about the loop demonstration pro-
gram. Firstly, the inner loop is defined as a separate function (a sub-process).
Locally defined integer variables s and t are used as loop counters, and the ++
Search WWH ::




Custom Search