A block is any code between curly braces {}. Variables declared inside a block only exist inside that block. This is called scope.
if (true) {
int x = 10;
System.out.println(x);
}
System.out.println(x); // Error: x is not defined here
The variable x is created when the block starts and destroyed when the block ends. Trying to use it outside the block causes a compile error.
If you need a variable after the if block, declare it before the block:
int x = 0;
if (true) {
x = 10;
}
System.out.println(x); // Works: prints 10
This applies to every block structure: if, else, switch, loops, and plain {} blocks. Each set of braces creates its own scope. Variables from an outer scope are visible inside inner blocks, but not the other way around.