Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Which loop is better ?

d4xtian
Participant
0 Likes
888

From an Input let's say '3' i want to display a product of that input from 1 to 10, but i want to skip the 5th iterration.
I made two loop and i would like to know if there is one that is better than an other in term of optimisation...

And yes i have already declare all variables and parameters.

Thanks

Loop1

WHILE v_y <= 10 .            " Loop the into the v_y  until it is equal 10

  IF v_y <> 5 .              " We check if v_y is different than 5
    v_res = p_x * v_y .
    WRITE :/ p_x,'*',v_y,'=',v_res .
  ELSE.                      " If v_y = 5 we skip and we do nothing

  ENDIF .
  v_y = v_y + 1 .            " We increment the v_y to go to the next number
ENDWHILE .

Loop 2

WHILE v_y <= 10 .            " Loop the mutiply until variable equal 10

  IF v_y = 5 .              " We check if v_y is different than 5
    v_y = v_y + 1 .         "We increment the v_y
    CONTINUE.
  ENDIF.
    v_res = p_x * v_y .
    WRITE :/ p_x,'*',v_y,'=',v_res .
    v_y = v_y + 1 .            " We increment the v_y to go to the next number
ENDWHILE .
3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
815

You should not waste time in optimizing few microseconds... Focus on expensive constructs only.

Read only

d4xtian
Participant
0 Likes
815

thank you sandra.rossi ,

what are you calling expensive construts ?

Read only

Sandra_Rossi
Active Contributor
815

expensive = database access, etc.