The loop() function is called over and over again. Every time the functions ends, all variables are lost.
That is: the local variables on the stack.
You can create a global variable, outside the loop() function.
That global variable is in ram and has it's own location, and stays there.
Another way is to use the word 'static'. That forces a local variable to be created in ram just as an global variable, and not on the stack. The variable is however only usable in the loop() function, the scope is still within the loop() function.
int supercars; // global variable.
void loop()
{
int berries;
static int clouds;
// supercars is global, it will keep its value.
supercars++;
// clouds is static, it will keep its value;
clouds += 3;
// berries is a variable on the stack, it will loose its value.
berries = 5;
}
A normal variable is only temporary. It is declared on the stack and unuseable after the functions ends. Did you know that you can create variables inside a for-loop or while-loop ? In that case the variable is 'extra' temporary so to speak. The scope of the variable is only within that loop.
Using global variables can make a bad sketch. Those variables can be changed in any function. A good sketch has a well-balanced use between global variables and normal variables and maybe a few 'static' variables. Every variable according to its use.