Code:int main() { int i,sum; do { printf("%d\n",sum); sum+=i*i; } while(i>3); { i=43; i-=3; if(i==23) break; } return(0); } error break statement not within loop or switch could someone tell me what is the problem,plesase?
This is a discussion on error (do-while)loop within the C Programming forums, part of the General Programming Boards category; Code: int main() { int i,sum; do { printf("%d\n",sum); sum+=i*i; } while(i>3); { i=43; i-=3; if(i==23) break; } return(0); } ...
Code:int main() { int i,sum; do { printf("%d\n",sum); sum+=i*i; } while(i>3); { i=43; i-=3; if(i==23) break; } return(0); } error break statement not within loop or switch could someone tell me what is the problem,plesase?
A little bit of formatting might help you see the error:
Is the break statement inside a loop, or switch statement?Code:int main() { int i,sum; do { printf("%d\n",sum); sum+=i*i; }while(i>3); { i=43; i-=3; if(i==23) break; } return(0); }
Jim
i m sorry, i fully dont understand the meaning of switch statement. Inside the loop.
It is not the switch statement that is not inside a loop. It is the break statement not inside a loop. A break must be either inside a loop or inside a switch statement. Is your break statement inside a loop? Inside a switch statement?
Jim
Inside a loop.
The problem is that the break statement is not inside a loop. Look at your code I re-posted, your break statement is not inside any loop.
Please see this link: Control Structures.
Jim
Is it? Where does your loop start (and how do you know?) and where does it end (and how do you know)? What would your loop look like, if it didn't do anything? Just the empty loop?
Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
Operating system: Ubuntu GNOME 13.04 (Raring Ringtail) (64-Bit) / Linux 3.8.0-16.26 / GNOME 3.6.2
Compiler: gcc 4.7.3
Ok... since nobody else has done this, so far...
Get it now?Code:int main() { int i,sum; do { printf("%d\n",sum); <---- this is your loop sum+=i*i; }while(i>3); { i=43; i-=3; <---- this is not. if(i==23) break; } return(0); }
If you want to know what a switch() statement is ... look it up!
yes.thank you.