Can any one say why the break state does not work.

#include<stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    loop:
    scanf("%d",&n);
    if(n!=42){
    printf("%d",n);
    goto loop;}
   else
    {
    break;
    }
   
    return 0;
}

this is my code.

The error is .....
14 E:\codechef.cpp break statement not within loop or switch

You can only use break within a loop, or a switch. The C++ loops are for, while and do-while. You have no loop, so you cannot use break.

Oh! yea.
Thanks a lot.
I got it.
Ohhhh!!!!!!.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.