The for loop

Advertisements
Advertisements
Advertisements3
Advertisements4
Advertisements6
Advertisements66

1. What is the difference between a while loop and a for loop?

Ans. A for loop is used when the number of iterations is known, while while loop is used when the number of iterations is unknown.

2. What will be the output of the following for loop? 

for (int i = 10; i >= 1; i /= 2) { System.out.print(i + ” “); }

Ans. 10 5 2 1.

 

Author: Lakshmi Prasanna Ponnala

Completed M.Tech in Digital Electronics and Communication Systems.

Leave a Reply

error: Content is protected !!

Discover more from ece4uplp

Subscribe now to keep reading and get access to the full archive.

Continue reading