0

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.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Anuradha Mandal
0

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.

Edited by Moschops: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.