Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

The C Programming Language - Break And Continue Statement

Loading...

Published in: C / C++
596 Views

Hi, Here I discussed C Program flow control statement one part Break and Continue statement

Uma / Madurai

3 years of teaching experience

Qualification: M.Sc (Rena Infotech, Cheranmahadevi - 2013)

Teaches: Advanced Excel, Basic Computer, Computer for official job, MS Office, School Level Computer, All Subjects, Biology, Computer Science, History, Social Studies, Geography, B.Sc Tuition, B.Tech Tuition, IT, M.Sc Tuition, C / C++, Java And J2EE, Visual Basic

Contact this Tutor
  1. Break and continue statment
  2. C — break statement The break statement ends the loop immediately when it is encountered. Its syntax is: reak;
  3. How to break statment works? while (test Expression) { if codes (condition to break) { break; codes do { // codes if (condition to break) { break; // codes while (testExpression) ; for (init; testExpression; update) { codes (condition to break) { break; codes
  4. Example // Program to calculate the sum of numbers (10 numbers max) // If the user enters a negative number, the loop terminates —#inelude <stdio.h> int main() { int i; double number, sum = 0.0; for (i printf("Enter n%d: t', i); &number);— // if the user enters a negative number, break the loop if (number < 0.0) { break; sum += number; // sum = sum + number; = %.21f', sum); return O;
  5. Output Enter nl: 2.4 Enter n2: 4.5 Enter n3: 3.4 Enter n4: -3
  6. C — Continue statement The continue statement skips the current iteration of the loop and continues with the next iteration. Its syntax is: continue;
  7. How continue statement works? while if (testExpression) { codes (testExpression) { continue; codes if while codes (testExpression) { continue; codes ( test Expression ) ; for (init; testExpression; update) { if codes (testExpression) { continue; codes
  8. Example / Program to calculate the sum of numbers (10 numbers max) // If the user enters a negative number, it's not added to the result #include <stdio.h> int main() int i; double number, sum = 0.0; for (1 printf("Enter a n%d: i); &number); if (number < 0.0) continue; sum += number; // sum = sum + number; printf("Sum = %.21f', sum); return O;
  9. Output Enter n I : 1.1 Enter n2: 2.2 Enter n3 : 5.5 Enter n4: 4.4 Enter n5 • . -3.4 Enter n6• . -45.5 Enter n7: 34.5 Enter n8: -4.2 Enter Enter n 10: 12 Sum 59.70