Sunday, January 11, 2009

FOR Loop

Oracle/PLSQL: FOR Loop


The syntax for the FOR Loop is:

FOR loop_counter IN [REVERSE] lowest_number..highest_number
LOOP
{.statements.}
END LOOP;

You would use a FOR Loop when you want to execute the loop body a fixed number of times.


Let's take a look at an example.

FOR Lcntr IN 1..20
LOOP
LCalc := Lcntr * 31;
END LOOP;

This example will loop 20 times. The counter will start at 1 and end at 20.


The FOR Loop can also loop in reverse. For example:

FOR Lcntr IN REVERSE 1..15
LOOP
LCalc := Lcntr * 31;
END LOOP;

This example will loop 15 times. The counter will start at 15 and end at 1. (loops backwards)

1 comment:

  1. Hi all,

    I am working for a software integrator company. My projects includes working on Java and Ruby on Rails and Ajax. I think Web Services is really cool. We also recently have to now work on REST and they are talking about mashups and Struts. Can anyone tell me if there are some good training or conferences so that me and my team members can get to speed with these technologies. Learning from books is not my cup of tea, even not when I was doing engineering ;)

    All the help that group members can provide in this regard is much appreciated.

    Thanks,
    Vaibhavi

    ReplyDelete