How to jump out from a for loop?

Rohit
Rohit
Teacher
76 Points
1 Posts

If there is a running 'for' loop in a program and we want to jump out from that loop before the loop terminated then how we can do this in C.

Views: 9491
Total Answered: 1
Total Marked As Answer: 1
Posted On: 29-May-2018 03:14

Share:   fb twitter linkedin
Use break statement to jump out.
 - beginer  29-May-2018 06:19
Answers
Smith
Smith
None
2568 Points
74 Posts
         

Use break to exit the loop, if your condition is met, before even going till the end

int x, i;
for(i=1;i<=10;i++){
  scanf("%d",&x);
  if(x>100)
     break;
  else
     printf ("%d\n", x);
}
Posted On: 29-May-2018 06:54
 Log In to Chat