-2
       for(OPV=230;OPV<245;OPV++)
       {
           for(IKW=1.3;IKW<=2.9;IKW++)
           {
               for(OKW=0.01;OKW<0.50;OKW++)
              {
                     for(OPI=0.05;OPI<0.50;OPI++)
                     {
                           OPV=OPV+1;
                           IKW=IKW++;
                           OKW=OKW++;

                           System.out.println( OPV+""+IKW+"+OKW+"+OPI")

My for loop is not giving me result as per the ranges I have given.suggest some modifications if any

Pooja
  • 39
  • 9

1 Answers1

5

When you increment the loop variable with OPI++, it is incremented by one. This means that the two inner most loops will have just one iteration.

You can set a smaller increment with, for example, OPI+=0.01, depending on your requirements.

Besides that, usually there's no point in incrementing the loop variables inside the loop body as you do, since that causes them to be incremented in both the loop's increment clause and the loop body.

Something like this may be what you want (though you may want to change the increments) :

for(OPV=230;OPV<245;OPV++) {
    for(IKW=1.3;IKW<=2.9;IKW+=0.1) {
        for(OKW=0.01;OKW<0.50;OKW+=0.01) {
            for(OPI=0.05;OPI<0.50;OPI+=0.01) {
                System.out.println(OPV + " " + IKW + " " + OKW + " " + OPI);
            }
        }
    }
}
Eran
  • 387,369
  • 54
  • 702
  • 768