How to jump out from a for loop?

Rohit
Rohit
Participant
6 Points
3 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: 8175
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
Participant
374 Points
112 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