Continue Statement - C Language Tutorial [C Programs]

Description

Continue statement is used when user wants to go back again to the start of that loop code, becuase of unexpected input entered by the user, program failure or any other purpose.

Source code

//Using continue statement
#include <stdio.h>
#include <conio.h>
void main()
{
int dividend,divisor,quotient,remainder;
char ch;
clrscr();
do
{
printf("Enter dividend : ");
scanf("%d", & dividend);
printf("Enter divisor : ");
scanf("%d",&divisor);
        if(divisor==0)
            {
              printf("Cannot divide by zero, pls try again.");
             continue;
}
quotient=divident/divisor;
remainder=divident%divisor;
printf("Quotient is : %d ,",quotient);
printf("Remainder is : %d",remainder);
printf("\nDo you want to do another calculation? (y/n)");
scanf("%c",&ch);
}while(ch!='n');
getch();
}

Program working steps

Its a simple divido program.
When a user attempts dividend divided by zero, it should not be allowed to proceed further for caluclation. So instead program should print 'cannot divide by zero, pls try again.' and start again from the starting of the loop. This can be implemented using continue statement.
Thats the main reason to use continue statement, rest of the program code is simple and easy to understand.

Thank you for sharing Your Knowledge with others who need It.-Team LetML

Post a Comment

Copyright © LetML. Blogger Templates Designed by OddThemes