class Sample {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
System.out.println(i); // `i` is accessible within the loop
}
// System.out.println(i); // Compilation error: `i` is out of scope here
// Defining a variable outside the loop to use it after the loop
int j;
for (j = 0; j < 3; j++) {
System.out.println(j); // `j` is accessible and modifiable within the loop
}
System.out.println(j); // Works fine, `j` is accessible here and holds the value 3
}
}