Computer Science, asked by SƬᏗᏒᏇᏗƦƦᎥᎧƦ, 4 months ago

Explain interconversion of loops with a example.
No googl'e use ​

Answers

Answered by Oreki
5

Conversion from for loop to while loop are often asked so, I will convert a basic for loop to a while loop in Java.

Example\ -

     \texttt{for (int i = 1; i < 20; i += 2) \{}

         \texttt{int number = i * 2}

         \texttt{System.out.println(number);}

     \texttt{\}}

To a while loop

    So, first declaration of the iteration variable,

         \texttt{int i = 1;}

    Then, the while loop,

         \texttt{while ( i < 20 ) \{}

             \texttt{int number = i * 2;}

             \texttt{System.out.println(number);}

          Now the updation/incrementation,

             \texttt{i += 2;}

         \texttt{\}}

Answered by Anonymous
4

conversion from for loop to while loop are often asked So, I will convert a basic for loop to a while loop in Java.

Example -

for (int i = 1 ; I < 20 ; i + = 2 ) {

int number = i* 2

system. out. print In (number) ;

}

To a while loop

So, first declaration of the iteration

variables,

int i = 1 ;

Then, the while loop,

while (i < 20) {

int number = i * 2

system. out. print In (number) ;

Now the updation/incremenation

i + = 2 ;

}

Explanation:

@Ask The MASTER

Similar questions