Final answer:
Yes, you can rewrite any for-loop as a while-loop. The for-loop's initialization, condition, and iteration parts are separated in the while-loop with initialization happening before the loop, condition as the loop's criteria, and iteration at the end of the loop body.
Step-by-step explanation:
The statement is true; you can rewrite any for-loop as a while-loop. Both types of loops are control flow statements that allow us to execute a block of code multiple times based on a condition. A for-loop typically includes the initialization, condition, and increment/decrement in one line, whereas a while-loop requires you to initialize before the loop and increment or decrement within the loop's body.
To convert a for-loop to a while-loop, you would take the initialization part of the for-loop and place it outside, before the while-loop begins. The condition part of the for-loop becomes the condition for the while-loop. Finally, you would place the increment or decrement part of the for-loop at the end of the while-loop's body. Here is a generic example showing this conversion:
// For-loop
for (int i = 0; i < 10; i++) {
// Code to repeat
}
// Equivalent While-loop
int i = 0;
while (i < 10) {
// Code to repeat
i++;
}