When the switch S is open, the current flows through the 10 Ω and 30 Ω resistors in series, and the total resistance is:
\[
R_{\text{total}} = 10 + 30 = 40 \, \Omega.
\]
Using Ohm's law:
\[
I = \frac{V}{R_{\text{total}}} = \frac{20}{40} = 0.5 \, \text{A}.
\]
Thus, the current through the 10 Ω resistor when the switch S is open is 0.5 A.
When the switch S is closed, the 30 Ω resistor is bypassed, and only the 10 Ω resistor remains in the circuit. The current through the 10 Ω resistor is:
\[
I = \frac{V}{R_{\text{total}}} = \frac{20}{10} = 2 \, \text{A}.
\]
Thus, the current through the 10 Ω resistor when the switch S is closed is 2 A.