Rewrite the following do while program segment using for:

ICSE Class 10 Computer Applications PYQ · 2024 Paper · Section A

2(iii)1 Mark · 2024 · Section A · 2024 Paper

Rewrite the following do while program segment using for:

x = 10; y = 20;
do
{
    x++;
    y++;
} while (x<=20);
System.out.println(x * y );
Show SolutionHide Solution↓

Below is the for loop version of the provided do-while segment:

public class Main {
    public static void main(String[] args) {
        int x = 10, y = 20;

        for (; x <= 20; x++, y++) {
            // Body is empty because the increments are in the for loop header
        }

        System.out.println(x * y);
    }
}
← Previous questionNext question →

Browse the free Computer Applications sample bank