Author |
Message
|
cadenza |
Posted: Mon Sep 20, 2004 10:20 pm Post subject: Breaking or Continuing a Loop in WMQI 2.1 |
|
|
Apprentice
Joined: 01 Jun 2004 Posts: 48
|
Dear All,
Is there a keyword / method through which I can break from the loop or continue a loop?
I am using WMQI 2.1 , CSD 07.
Thanks. |
|
Back to top |
|
 |
kirani |
Posted: Mon Sep 20, 2004 10:28 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Have you looked at the WHILE statement.
Code: |
DECLARE MYVAR BOOLEAN TRUE;
While (MYVAR)
....
....
....
....
if ( exit_loop) THEN
SET MYVAR = FALSE;
END IF;
END WHILE;
|
_________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
cadenza |
Posted: Mon Sep 20, 2004 10:42 pm Post subject: |
|
|
Apprentice
Joined: 01 Jun 2004 Posts: 48
|
Hi Kiran,
Thanks for your reply.
I have used such a logic before. But the problem at hand is
while(condition)
...
...
break or continue condition
...
...
end while.
How do I deal with this? |
|
Back to top |
|
 |
cadenza |
Posted: Mon Sep 20, 2004 10:50 pm Post subject: |
|
|
Apprentice
Joined: 01 Jun 2004 Posts: 48
|
Hi ,
Adding to my previous post.
The break or continue condition may be misleading.
Actually I have to decide on 3 conditions there:
Either I break , Or I continue (i.e. the loop restarts with updated counter) , or I proceed normally to the next statement.
So, in reality it is a 3 way branching.
Also the while indicated is within 5-6 levels of loops. I am looking for a suitable optimum method.
Thanks. |
|
Back to top |
|
 |
mgk |
Posted: Tue Sep 21, 2004 12:04 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
I can't rememver what version they were introduced in, but the statements you are looking for are CONTINUE and LEAVE, possible with a labled on the loop. This is certainly in V5, but I'm not sure about earlier. If not you could always be really ugly and put the part of the while loop you need to skip in an IF statement...
Cheers, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
cadenza |
Posted: Tue Sep 21, 2004 1:38 am Post subject: |
|
|
Apprentice
Joined: 01 Jun 2004 Posts: 48
|
Hi,
I tried the following:
SET I = 1;
WHILE ( I < 10 ) DO
IF ( I = 3 ) THEN
LEAVE; / BREAK; / CONTINUE;
END IF;
SET I = I + 1;
END WHILE;
In all the above 3 cases I received a Syntax Error notation indicating that WMQI could not recognize it.
So, I believe I have run out of luck this time.
Thanks. |
|
Back to top |
|
 |
mgk |
Posted: Tue Sep 21, 2004 2:19 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi, So the CONTINUE / LEAVE is V5 only (BREAK is not part of ESQL)
but what (apart from being ugly) is wrong with:
SET I = 1;
WHILE ( I < 10 ) DO
IF ( I = 3 ) THEN
SET I = 10;
ELSE
-- other code here
SET I = I + 1;
END IF;
END WHILE;
or, even:
Or something similar:
DECLARE test BOOLEAN TRUE;
WHILE ( test ) DO
IF ( somecondition ) THEN
SET test = FALSE;
ELSE
-- other code here
END IF;
END WHILE; _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
Missam |
Posted: Tue Sep 21, 2004 6:08 am Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
This can be acheived by adding a flag to your control.
like kirani suggested
Code: |
While (i < number and flag = true) do
--
--
--
if (condition) then
set flag = flase;
end if
--
--
end while; |
|
|
Back to top |
|
 |
kirani |
Posted: Tue Sep 21, 2004 1:08 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
cadenza,
What version of CSD are you using? I think these statements (CONTINUE, LEAVE, ..) are introduced in CSD3/4 of WMQI. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
mgk |
Posted: Tue Sep 21, 2004 1:25 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi cadenza,
I suspect that kirani maybe right, and I also noticed a syntax error in the code you posted. The LEAVE and CONTINUE statements require a label like this:
myLoop: WHILE ( I < 10 ) DO
SET OutputRoot.XML.Top.Result.i[I] = I;
IF I = 3 THEN
LEAVE myLoop;
END IF;
SET I = I + 1;
END WHILE myLoop ;
Cheers, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
cadenza |
Posted: Wed Sep 22, 2004 2:56 am Post subject: |
|
|
Apprentice
Joined: 01 Jun 2004 Posts: 48
|
Hi All,
Thanks for your reply.
The LEAVE myLoop; doesnt give any syntax error. Unfortunately if I replace the statement with CONTINUE myLoop; then it shows syntax error.
So, could you please tell me how to use CONTINUE.
By the way the WMQI version is
Version: 530.7 CSD07
Thanks.[/quote] |
|
Back to top |
|
 |
kirani |
Posted: Wed Sep 22, 2004 7:07 am Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Do you get syntax error in Editor or when doing a deploy. If it's in the editor then I'd suggest try deploying the message flows. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
|