Search
 
SCRIPT & CODE EXAMPLE
 

C

C break statement

// Program to calculate the sum of numbers (10 numbers max)
// If the user enters a negative number, the loop terminates
#include <stdio.h>
int main() {
   int i;
   double number, sum = 0.0;
   for (i = 1; i <= 10; ++i) {
      printf("Enter n%d: ", i);
      scanf("%lf", &number);
      // if the user enters a negative number, break the loop
      if (number < 0.0) {
         break;
      }

      sum += number; // sum = sum + number;
   }
   printf("Sum = %.2lf", sum);
   return 0;
}
Comment

break used in loops in c

for (int i = 0; i <= 10; i++) {
  if (i == 4 && someVariable == 10) {
    break;
  }
}
Comment

PREVIOUS NEXT
Code Example
C :: turn a char array into double C 
C :: function array median 
C :: c program for swapping of two numbers 
C :: transfer function exponent matlab 
C :: c print characters 
C :: sockaddr_in c 
C :: Float and Double Input/Output 
C :: how to change file permissions in C language 
C :: increment and decrement operator 
C :: sleep in c 
C :: text to hex in C 
C :: sqrt function in c 
C :: c check if character is a digit or alphabet 
C :: c malloc array 
C :: majuscule en c 
C :: c calling a function 
C :: bitwise operators 
C :: c sjf 
C :: largest value in u64 
C :: find all hyperlinks <a in p tag 
C :: User input in struct 
C :: bool print variable in c 
C :: error: invalid type for iteration variable ‘i’ #pragma omp parallel for 
C :: Uri/beecrowd problem no - 1131 solution in C 
C :: how to alias an awk command 
C :: how to initiate pointer array with null in c 
C :: esp rainmaker led 
C :: nc,manc 
C :: lazer codechef 
C :: email dev Microsoft Outlook 2007 items all aligned left or aligned wrong 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =