Computer Science, asked by muz9225, 2 months ago

Convert the following segment into equivalent for loop.
int x =5, y=50;
while( x<=y)
{
System.out.println (“X =” +x);
x=x+5;
}​

Answers

Answered by anindyaadhikari13
4

SOLUTION.

Given cøde –

int x = 5, y = 50;

while(x <= y){

      System.out.println("X = "+x);

      x = x + 5;

}

After conversion, we get, –

for(int x = 5, y = 50; x <= y; x = x + 5)

    System.out.println("X = "+x);

STEPS.

  • Declare and initialise the control variables.
  • Write the test conditions.
  • Write statement to update the control variable.
  • Write the statement whose execution is to be repeated inside opening and closing curly brackets {}.
Similar questions