ALT Linux Community general discussions
 help / color / mirror / Atom feed
* [Comm] strange loop in PERL
@ 2007-05-12 15:37 Aleksander N.Gorohovski
  2007-05-14  7:57 ` ABATAPA
  0 siblings, 1 reply; 2+ messages in thread
From: Aleksander N.Gorohovski @ 2007-05-12 15:37 UTC (permalink / raw)
  To: community

Доброго времени суток сообщество!

Обнаружил странное (необычное) выполнение циклов в PERL.
Странность заключается в том, что прерывание (командой last) одного цикла
сказывается на выполнении такого же другого следующего
(в нём пропускается одна первая иттерация).
:(

Вот пример программки:
#----------------------------------------------
#!/usr/bin/perl

%w=('a'=>'1', 'b'=>'2');

$Dmax=1; $Dmin=0;

$Hr=120; $h=0;

$Tmax=100; $Tmin=0;

while(abs($Hr-$h)>=.1){
     $h++;
     print"\n$h\t";

# !!!!!!   ERROR   !!!!!!!!!!!!
     while(my($n,$v)=each(%w)){
	print"$n => $v\t";
     }
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

     if(abs($Tmax-$Tmin)<.1){

	while(my($n,$v)=each(%w)){
	    next if $Dmax-$Dmin<0.0001;
	
	    $Dmin=$alf if $h<$Hr;
	    $alf=($Dmin+$Dmax)/2;

	    last; #!!!!   ERROR   !!!!!!!
	}
     }else{
	$Tmin++;
     }
}
exit;
#----------------------------------------------
Если один из while-циклов поменять, например, на for -- странность  
исчезнет.

Может кто покомментировать это?
или Ларри надо писать.

Спасибо.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Comm] strange loop in PERL
  2007-05-12 15:37 [Comm] strange loop in PERL Aleksander N.Gorohovski
@ 2007-05-14  7:57 ` ABATAPA
  0 siblings, 0 replies; 2+ messages in thread
From: ABATAPA @ 2007-05-14  7:57 UTC (permalink / raw)
  To: ALT Linux Community

12 мая 2007 г. Aleksander N.Gorohovski написал:
> Может кто покомментировать это?
Как обычно, сведите пример к МИНИМУМУ.

PS: Это еще что, а вот поведение кода ' $i=5; $i=++$i + ++$i; 
printf("%d\n",i);' в PHP забавно...

-- 
ABATAPA


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-05-14  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-12 15:37 [Comm] strange loop in PERL Aleksander N.Gorohovski
2007-05-14  7:57 ` ABATAPA

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git