RE: basic question for loop

RE: basic question for loop

 

  

Nobody likes GOTOs.
But, Here's an example that might work for
you from the documentation.

The label end_loop in the following example
is not allowed because it does not precede
an executable statement:

DECLARE
done BOOLEAN;
BEGIN
...
FOR i IN 1..50 LOOP
IF done THEN
GOTO end_loop;
END IF;
...
<<end_loop>> -- not allowed
END LOOP; -- not an executable statement
END;


To debug the last example,
just add the NULL statement, as follows:

FOR i IN 1..50 LOOP
IF done THEN
GOTO end_loop;
END IF;
...
<<end_loop>>
NULL; -- an executable statement
END LOOP;



-----Original Message-----
From: Abhishek.Goel
[mailto:oracledba-ezmlmshield-x16605174.[Email address protected]
Sent: Wednesday, August 02, 2006 3:07 PM
To: LazyDBA Discussion
Subject: RE: basic question for loop


Hi All

I think I didn't clearly wrote my requirement. My requirement is to come to start of loop whenever I need. I am looking for some command like 'BREAK' , which immediately comes out of the loop. Here instead of going out, I want to go to 'start' of the loop.
It should be just like 'CONTINUE" command in some of the languages which takes control to the start of loop.

FOR I in 1..4 LOOP
IF I=2 THEN
<< here I want to go to start of loop for next value of I>>
ELSE
DBMS_OUTPUT.PUT_LINE('value of I is ' || I);
END IF;

<<some other executable statements>>
END LOOP;



-----Original Message-----
From: Ning Wong [mailto:[Email address protected]
Sent: Wednesday, August 02, 2006 4:58 PM
To: Abhishek.Goel
Subject: RE: basic question for loop

**A LazyDBA.com subscriber has responded to your lazydba.com post**
**LazyDBA.com mail shield has forwarded you this email,
**and removed any attachments, and kept your email address secret
**from this person, and any viruses/trojans.
**If you reply to this email, the person will see your email address as normal
**Anything below this line is the original email text


FOR I in 1..4 LOOP
IF I=2 THEN
<< here I want to go to start of loop for next value of I>>

null; --

ELSE
DBMS_OUTPUT.PUT_LINE('value of I is ' || I);
END IF;
END LOOP;


or

FOR I in 1..4 LOOP
IF I<>2 THEN
DBMS_OUTPUT.PUT_LINE('value of I is ' || I);
END IF;
END LOOP;

-----Original Message-----
From: Abhishek.Goel
[Email address protected]
Sent: Wednesday, August 02, 2006 2:53 PM
To: LazyDBA Discussion
Subject: basic question for loop


Hi All

I have one basic question..
I have one FOR LOOP and want to goto start of loop for next value of I, NOTE: I am not suppose to use GOTO statement.

FOR I in 1..4 LOOP
IF I=2 THEN
<< here I want to go to start of loop for next value of I>>
ELSE
DBMS_OUTPUT.PUT_LINE('value of I is ' || I);
END IF;
END LOOP;


--------
website: http://www.LazyDBA.com
Please don't reply to RTFM questions
Oracle documentation is here: http://tahiti.oracle.com
To unsubscribe: see http://www.lazydba.com/unsubscribe.html
To subscribe: see http://www.lazydba.com
By using this list you agree to these terms:http://www.lazydba.com/legal.html




--------
website: http://www.LazyDBA.com
Please don't reply to RTFM questions
Oracle documentation is here: http://tahiti.oracle.com
To unsubscribe: see http://www.lazydba.com/unsubscribe.html
To subscribe: see http://www.lazydba.com
By using this list you agree to these terms:http://www.lazydba.com/legal.html



--
This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

Douglas County, Oregon
www.co.douglas.or.us


Oracle LazyDBA home page