How to control for loop using break and continue statements in C#?

Break statement terminates the loop. To use it in a for loop, you can get input from user everytime and display the output when user enters a negative number. The output gets displayed then and exited using the break statement −

for(i=1; i 

In the same way, continue statement in a for loop works, but it will not display the negative numbers. The continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating −

for(i=1; i 
Updated on: 2020-06-20T16:05:10+05:30

271 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements