title: will a break statment break out of a while loop and an other if loop?
body: <p>I have a thread that logs serial data from a USB port. When the semaphore is posted and the variable <code>serial_logging_running</code> is <code>1</code> it proceeds to the <code>while(serial_logging_running == 1)</code> loop and continually reads the serial port and writs to file. When the program is exited the signal handler sets the variable <code>serial_logging_running</code> to <code>0</code>. Will the <code>break</code> statement exit the <code>while()</code> loop and the outside <code>if (res == 0)</code> and then proceed to return null statement?</p>
  
  <pre><code>static void *logging(void *param) {
  
      int rdlen, res;
      char ibuf[1024];
  
      sem_wait(&amp;logging_semaphore); 
  
      /*Open log file and write to it from /dev/USB1*/
      create_open_log_file();
      res = log_dut_serial_data(serial_port);
  
      if (res) {
          fprintf(stderr,"Error opening the serial port%s\n",serial_port);
      }
  
      if (res == 0) {
  
          while(serial_logging_running == 1) {
  
              /*read from serial port write to log file*/
              rdlen = read(fd_joule, ibuf, sizeof(ibuf));
  
              if (rdlen &gt; 0) {
                  fwrite(ibuf, sizeof(char), rdlen, log_file);
                  fflush(log_file);
              }
  
              if (rdlen &lt; 0) {
                  fprintf(stderr, "rdlen les than 0\r\n");
              }
  
              /* Exit the serial logging thread*/
              if (serial_logging_running == 0) {
                  printf("Exiting serial logging thread\r\n");
                  break;
              }
  
  
          }
      }
  
      close_serial_port_joule(); /*Exiting close the serial port*/
  
      return NULL;
  
  }
  </code></pre>