Investigate 10.2.
Is there a difference between the two following scenarios, if the same statements are used within each element?
-
Nesting an
ifstatement within a loop -
Nesting a loop within an
ifstatement
for and if together
if statement inside a loop or a loop inside an if statement.
Compile and run the code below in your own C environment.
#include <stdio.h>
int main(void)
{
int i;
int p = 3;
printf("Printing numbers divisible by %d: \n", p);
for (i=0; i<p*10; i++){
if (i%p==0)
printf("\n%d\n", i);
else
printf("-");
}
return(0);
}
if statement within a loopif statement