CodesandTutorials
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.
You are here - Home > Programming > C > Basics

Continue Statement


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.

Tip Box

Use it where you think, there are chances of unneccessary error may occur.


Advertisement





Terms of Use | Privacy Policy | Contact Us | Advertise
CodesandTutorials © 2014 All Rights Reserved