user3826: I am experiencing some very strange behavior with my arduino. I have a switch-case statement in the loop() method, and the break methods are not only breaking out of the case block, but also out of the loop() statement. Is this normal, and if so, how can I edit the structure so it doesn't do that?
My code structure looks like this:
void loop(){
  switch(int i){
    case 1:{
      //do something
      break;// this also breaks out of the loop() method.
    }
  }
}


user2967: Your sample is too simple to test your hypothesis (which is wrong, by the way.)
Set up serial output so you can test:
void loop()
{
  Serial.println("Before switch statement");
  int i = 1;
  switch (i)
  {
    case 1:
      Serial.println("In case 1");
      break;
    default:
      Serial.println("In default case");
  }
  Serial.println("After switch statement.");
}

You can even add an outer for loop to make things a little more complicated:
void loop()
{
  Serial.println("Before for loop statement");
  for (int i = 1; i< 10; i++)
  {
    Serial.print("In for loop before switch, i = ");
    Serial.println(i);
    switch (i)
    {
      case 1:
        Serial.println("In case 1");
        break;
      default:
        Serial.println("In default case");
    }
    Serial.println("After switch statement.");
  }
}

Examine the output on the serial monitor of your computer. You should find that the "After switch statement" line always appears after the "before switch..." line in both versions of the code.
Break breaks from the innermost scope. If you have nested levels of scope, like a function and then a switch statement inside the function, the break statement breaks out of that inner level. In the second example, the break broke out of the switch but the for loop kept running.
This is very basic C programming and not specific to Arduino.

user3826: I just realized it wasn't the sketch, but a faulty SD card reader on my computer corrupted my SD card. BIG TIME.

3826: <p>I am experiencing some very strange behavior with my arduino. I have a switch-case statement in the loop() method, and the break methods are not only breaking out of the case block, but also out of the loop() statement. Is this normal, and if so, how can I edit the structure so it doesn't do that?
My code structure looks like this:</p>

<pre><code>void loop(){
  switch(int i){
    case 1:{
      //do something
      break;// this also breaks out of the loop() method.
    }
  }
}
</code></pre>
 2967: <p>Your sample is too simple to test your hypothesis (which is wrong, by the way.)</p>

<p>Set up serial output so you can test:</p>

<pre><code>void loop()
{
  Serial.println("Before switch statement");
  int i = 1;
  switch (i)
  {
    case 1:
      Serial.println("In case 1");
      break;
    default:
      Serial.println("In default case");
  }
  Serial.println("After switch statement.");
}
</code></pre>

<p>You can even add an outer for loop to make things a little more complicated:</p>

<pre><code>void loop()
{
  Serial.println("Before for loop statement");
  for (int i = 1; i&lt; 10; i++)
  {
    Serial.print("In for loop before switch, i = ");
    Serial.println(i);
    switch (i)
    {
      case 1:
        Serial.println("In case 1");
        break;
      default:
        Serial.println("In default case");
    }
    Serial.println("After switch statement.");
  }
}
</code></pre>

<p>Examine the output on the serial monitor of your computer. You should find that the "After switch statement" line always appears after the "before switch..." line in both versions of the code.</p>

<p>Break breaks from the innermost scope. If you have nested levels of scope, like a function and then a switch statement inside the function, the break statement breaks out of that inner level. In the second example, the break broke out of the switch but the for loop kept running.</p>

<p>This is very basic C programming and not specific to Arduino.</p>
 3826: <p>I just realized it wasn't the sketch, but a faulty SD card reader on my computer corrupted my SD card. BIG TIME.</p>
