17th Nov 2022, 7:09 AM
Sahithi Polunati
Sahithi Polunati - avatar
9 Answers
+ 1
Then you can like if condition if(n%3==0) or if you want to break in even condition also or odd condition then you can write like: if(n%2==0) { break; } else { break; } I hope it's clear to you
17th Nov 2022, 7:28 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 1
I want to break the loop if an odd number is entered
17th Nov 2022, 7:19 AM
Sahithi Polunati
Sahithi Polunati - avatar
+ 1
Thank you
17th Nov 2022, 7:41 AM
Sahithi Polunati
Sahithi Polunati - avatar
+ 1
Sahithi Polunati the code has an unnecessary use of the break statement. To exit the loop, put the condition in the while statement. do { printf("enter a number n: "); scanf("%d", &n); printf("%d \n",n); } while (n%2==0); //loop while even
18th Nov 2022, 5:17 AM
Brian
Brian - avatar
0
#include <stdio.h> int main() { int n; do{ printf("enter a number n: "); scanf("%d", &n); printf("%d \n",n); if(n%2==0) { break; } } while(1); printf("thank you"); return 0; }
17th Nov 2022, 7:11 AM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
0
#include <stdio.h> int main() { int n; do{ printf("enter a number n: "); scanf("%d", &n); printf("%d \n",n); if(n%2!=0) { break; } } while(0); printf("thank you"); return 0; }
19th Nov 2022, 4:21 AM
Kripal Garaiya
Kripal Garaiya - avatar
0
Kripal Garaiya đŸ€” while (0)⁉ đŸ€Š
19th Nov 2022, 7:35 AM
Brian
Brian - avatar
0
Yes
19th Nov 2022, 7:44 AM
Kripal Garaiya
Kripal Garaiya - avatar
0
Try it
19th Nov 2022, 7:44 AM
Kripal Garaiya
Kripal Garaiya - avatar