Stop a simulation

Hello,

I'm new in this huge world of Arduino and right now i'm having big problems with a University project. Here's is my question. I hope someone will be able to help me. I'll do my best to explain the situation:
I have the following sketch, and when i run there's no way to stop. I mean if I want to stop the simulation i have to close the IDE software and open it again. Is there any way to stop the infinite loop like a command (break) or a key combination to stop it or a function?

What the program does basically is transform de voltage from the NTC to Temperature.
Here is the sketch (i took it from arduino's playground web page):

Link: Arduino Playground - Thermistor2

Thanks in advance!

#include <math.h>
//Schematic:
// [Ground] ---- [10k-Resistor] -------|------- [Thermistor] ---- [+5v]
// |
// Analog Pin 0

double Thermistor(int RawADC) {
// Inputs ADC Value from Thermistor and outputs Temperature in Celsius
// requires: include <math.h>
// Utilizes the Steinhart-Hart Thermistor Equation:
// Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3}
// where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08
long Resistance; double Temp; // Dual-Purpose variable to save space.
Resistance=10000.0*((1024.0/RawADC) - 1); // Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024 /ADC -1) * BalanceResistor
// For a GND-Thermistor-PullUp--Varef circuit it would be Rtherm=Rpullup/(1024.0/ADC-1)
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later. // "Temp" means "Temporary" on this line.
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp)); // Now it means both "Temporary" and "Temperature"
Temp = Temp - 273.15; // Convert Kelvin to Celsius // Now it only means "Temperature"

// BEGIN- Remove these lines for the function not to display anything
Serial.print("ADC: "); Serial.print(RawADC); Serial.print("/1024"); // Print out RAW ADC Number
Serial.print(", Volts: "); printDouble(((RawADC*4.860)/1024.0),3); // 4.860 volts is what my USB Port outputs.
Serial.print(", Resistance: "); Serial.print(Resistance); Serial.print("ohms");
// END- Remove these lines for the function not to display anything

// Uncomment this line for the function to return Fahrenheit instead.
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit
return Temp; // Return the Temperature
}

void printDouble(double val, byte precision) {
// prints val with number of decimal places determine by precision
// precision is a number from 0 to 6 indicating the desired decimal places
// example: printDouble(3.1415, 2); // prints 3.14 (two decimal places)
Serial.print (int(val)); //prints the int part
if( precision > 0) {
Serial.print("."); // print the decimal point
unsigned long frac, mult = 1;
byte padding = precision -1;
while(precision--) mult *=10;
if(val >= 0) frac = (val - int(val)) * mult; else frac = (int(val) - val) * mult;
unsigned long frac1 = frac;
while(frac1 /= 10) padding--;
while(padding--) Serial.print("0");
Serial.print(frac,DEC) ;
}
}

void setup() {
Serial.begin(115200);
}

#define ThermistorPIN 0 // Analog Pin 0
double temp;
void loop() {
temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius
Serial.print(", Celsius: "); printDouble(temp,3); // display Celsius
temp = (temp * 9.0)/ 5.0 + 32.0; // converts to Fahrenheit
Serial.print(", Fahrenheit: "); printDouble(temp,3); // display Fahrenheit
Serial.println(""); // End of Line
delay(100); // Delay a bit... for fun, and to not Serial.print faster than the serial connection can output
}
@]%%

You have posted code without using code tags. This creates certain problems and obstacles for other forum members. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the [code] and [/code] metatags.

When you are finished that, please read this post:

How to use this forum - please read.

The very nature of Arduino sketches is that they run forever. If you don't want to see any more output, just close the serial monitor. To stop the sketch, just pull the power from the Arduino.

If you want to have the thing run once only, move the contents of loop() to be the last lines of setup(). But be sure to leave the structure of loop intact, thusly:

void loop()
{
}

That said, you could pause the loop() with a switch like this. First choose a pin to use for the switch and wire the switch across that pin and ground. (Or, just stick a wire in the pin hole and jab the other end into one of the GND pin holes when you want to close the switch.)

At the top of the code (but not inside any of the functions) put something like this:

byte pausePin = 5;  //or whatever name and number you like.

Then inside the setup() function put this:

pinMode(pausePin, INPUT_PULLUP);

Then make this the last part of loop():

while (!digitalRead(pausePin))
{
}

When the switch is open, pausePin will be HIGH and the while() will be ignored and the program will loop back to the top of loop(). If you close the switch, pausePin will be LOW so the code will sit looping in the while(), but read the switch each time through. So if the switch is then opened, pausePin will be HIGH, the while will exit, and loop() will carry on as before.

Two questions though:

Why do you want to stop the skecth?
Why do you refer to this as a "simulation"?