[OpenSIPS-Users] Break in while loop
SamyGo
govoiper at gmail.com
Tue Jun 14 14:54:24 CEST 2016
Hi Husnain,
Simple *return* should work fine in your scenario but if everything fails
you can do some additional condition check in while() loop to break it !
for example:
$avp(flag) = 0;
while( ($var(i) < 10) && $avp(flag) != 1) {
if(condition){
$avp(flag) = 1;
}
}
I checked some of my other scripts and return was doing its job just fine.
Make sure you only execute 'return' only and not 'return(1)';
Regards,
Sammy
On Tue, Jun 14, 2016 at 8:05 AM, Husnain Taseer <husnain.taseer at gmail.com>
wrote:
> Dear Users,
> I am trying to break the while loop in opensips.cfg when a particular
> condition meet. For that I am using 'break' statement inside a while loop.
> But when I type break it gives me sytax error :
>
> Jun 14 06:56:00 s81519 opensips: CRITICAL:core:yyerror: parse error in
> config file /usr/local/etc/opensips/opensips.cfg, line 697, column 5-10:
> syntax error
> Jun 14 06:56:00 s81519 opensips: CRITICAL:core:yyerror: parse error in
> config file /usr/local/etc/opensips/opensips.cfg, line 697, column 5-10:
> bad command!)
> Jun 14 06:56:00 s81519 opensips: CRITICAL:core:yyerror: parse error in
> config file /usr/local/etc/opensips/opensips.cfg, line 697, column 5-10:
> bad command!)
> Jun 14 06:56:00 s81519 opensips: ERROR:core:main: bad config file (3
> errors)
> Jun 14 06:56:00 s81519 opensips: NOTICE:core:main: Exiting....
>
> If I will use return instead of break it will return from the current
> route which is also not my requirement. Below is the code snippet.
>
> $var(i) = 0;
> while($var(i) < 10) {
> usleep("20000");
> cache_raw_query("redis:group2","HGETALL $avp(dialed)","$avp(result)");
> if ($avp(result) != NULL) {
> $avp(CALLER) = $(avp(result)[1]);
> $avp(LRN) = $(avp(result)[3]);
> xlog("L_NOTICE","[$Ts:$avp(cid)]: LRN Returned '$avp(LRN)'");
> break; #Line number 697
> }
> $var(i) = $var(i) + 1;
> }
>
> Please guide.
>
> Regards,
> Husnain Taseer
> VoIP Developer
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20160614/80a59069/attachment.htm>
More information about the Users
mailing list