Home / Questions / Differentiate between the following code fragments and also give their output :- int f = 1, i = 2; while (++i < 5) f *= i; System.out.println(f); int f = 1, i = 2; do { f *= i; } while (++i < 5); System.out.println(f);
Explanatory Question

Differentiate between the following code fragments and also give their output :-

int f = 1, i = 2;

while (++i < 5)
    f *= i;

System.out.println(f);



int f = 1, i = 2;

do {
    f *= i;
} while (++i < 5);

System.out.println(f);

👁 64 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


Differentiate between the following code fragments and also give their output :-


int f = 1, i = 2;

while (++i < 5)
    f *= i;

System.out.println(f);




int f = 1, i = 2;

do {
    f *= i;
} while (++i < 5);

System.out.println(f);
This image is related to the question topic and helps improve visual understanding.