causing it to jump to the next iteration. Consider the following example.
/* Program-5.9 */
#include <stdio.h>
int main()
{
int i;
for(i=-5;i<=5;i++) // loop from -5 to 5
{
if (i == 0) // if 0 skip
continue;
printf("5 divided by %d is: \t %.2f \n", i, (5.0/i));
}
return 0;
}
In program-5.9, 5 is divided by all the integers from -5 to +5. However a number should not be
divided by 0. In Program-5.9, when “i” is 0 (when the if condition is TRUE) the continue keyword
is used to skip the rest of the iteration which will skip the printf function.
/* Program-5.9 */
#include <stdio.h>
int main()
{
int i;
for(i=-5;i<=5;i++) // loop from -5 to 5
{
if (i == 0) // if 0 skip
continue;
printf("5 divided by %d is: \t %.2f \n", i, (5.0/i));
}
return 0;
}
In program-5.9, 5 is divided by all the integers from -5 to +5. However a number should not be
divided by 0. In Program-5.9, when “i” is 0 (when the if condition is TRUE) the continue keyword
is used to skip the rest of the iteration which will skip the printf function.
No comments:
Post a Comment