| | |
break statement
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I have this sample program where the compiler gives me error for the break statement.
The error is " misplaced break in afunction"
Could anyone help me understanding why the break statement gives an error? i understand that u can use break in a for , while loop etc., and exit early when required.
thanks for the help
I have this sample program where the compiler gives me error for the break statement.
The error is " misplaced break in afunction"
Could anyone help me understanding why the break statement gives an error? i understand that u can use break in a for , while loop etc., and exit early when required.
thanks for the help
C++ Syntax (Toggle Plain Text)
#include <iostream.h> void afunction() { if(1) { cout<<"Err"; break; } } int main () { afunction(); }
Last edited by Ancient Dragon; Jan 16th, 2009 at 6:23 pm. Reason: add code tags
•
•
Join Date: Oct 2008
Posts: 44
Reputation:
Solved Threads: 11
•
•
•
•
#include <iostream.h>
void afunction()
{
if(1)
{
cout<<"Err";
break;
}
}
int main ()
{
afunction();
}
and exit early when required.
break statement you were trying to return back to the main() function.Placing a
C++ Syntax (Toggle Plain Text)
return;//Instead of break might be what you are looking for
Probably because the above program is a 'test' program(or something of that sort)
![]() |
Similar Threads
- "Break" (C)
- break statement (Python)
- If....else password statement (C++)
- Break statments confuse me, need some help (C++)
Other Threads in the C++ Forum
- Previous Thread: Array question
- Next Thread: get key input without pausing the program
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






