Thread: Error : Misplaced Break

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    21

    Error : Misplaced Break

    Here is my program.

    When I compile I get error misplaced break

    Code:
    #include<conio.h>
    #include<iostream.h>
    void main()
    {
     int i=1,total=0;
     clrscr();
     if(i<10)
     {
      total=total+1;
      i++;
      if(i==5)
      break;
     }
     cout<<"total";
     getch();
    }
    What I am doing wrong ?

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    break is intended to break out of a loop or switch case. Did you mean to use while instead of if on line 7?

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    21
    Quote Originally Posted by Matticus View Post
    break is intended to break out of a loop or switch case. Did you mean to use while instead of if on line 7?
    Thank you.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,408
    > #include<conio.h>
    This header file is obsolete.

    > #include<iostream.h>
    If your compiler doesn't accept
    #include <iostream>
    Then it too is obsolete.

    > void main()
    This is just wrong.
    main returns int, not void.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Misplaced else
    By Username changed in forum C++ Programming
    Replies: 3
    Last Post: 01-27-2014, 08:29 PM
  2. Replies: 4
    Last Post: 04-05-2011, 11:55 AM
  3. Misplaced else in function main -- help?
    By rollyah in forum C Programming
    Replies: 15
    Last Post: 04-30-2010, 12:55 PM
  4. Break two loops with a error
    By Cassady in forum C++ Programming
    Replies: 7
    Last Post: 05-07-2009, 04:50 PM
  5. misplaced )
    By blight2c in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2002, 07:44 PM

Tags for this Thread