CodesandTutorials
Home   Programming   Hardware   Networking
 
Next generation website theme is here (black, neon and white color) - Reduces eye strain and headache problems.  

C Categories

Continue Statement

« Previous Point - Break Statement Next Point - Goto 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.

« Previous Point - Break Statement Next Point - Goto Statement »

Tip Box

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


Advertisement

Rate Website
   

 


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