int a, b; for ( a=10 , b=1; a>=1 ; a-=2) { b+=a; b++; } System.out.print(b);
To convert the given for loop into an exit-controlled loop (i.e., a do-while loop), we need to ensure that the loop body executes at least once before checking the condition.
int a = 10, b = 1; do { b += a; b++; a -= 2; } while (a >= 1); System.out.print(b);
Initialization: a = 10, b = 1
Loop Execution: The loop executes at least once before checking a >= 1.
Update: a is decremented by 2 in each iteration.
Condition Check: The loop continues as long as a >= 1.
This ensures the loop behaves the same way as the original for loop but follows an exit-controlled structure.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.