Hi all, I am having problem with array while setting the flag, actaully when i get the array size should be all 44 other wise it should come to flag 0, now my array counts are 42 42 44, so it shows the flag 0, but for me it showing flag =1 , i think i have some loop problem, please let me know why? @split_record.each do |v| @split_data=v.split("\*") @get_size=@split_data.size // after split my array is 42 42 44 if @get_size == 44 @flag=1 else @flag=0 end end return @flag In this i am checking 3 records, i should get flag=1 if all are 44, but at present not matching, so it should shows floag=0, but for its showing flag =1, please let me know the problem, thanks in advance -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You should seriously consider reading http://whytheluckystiff.net/ruby/pickaxe/ And this question is suited for ruby-lang On 10/16/07, Vidya Vidya <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi all, > > I am having problem with array while setting the flag, > > actaully when i get the array size should be all 44 other wise it should > come to flag 0, now my array counts are 42 42 44, so it shows the flag > 0, but for me it showing flag =1 , i think i have some loop problem, > please let me know why? > > @split_record.each do |v| > @split_data=v.split("\*") > @get_size=@split_data.size // after split my array is > 42 42 44 > if @get_size == 44 > @flag=1 > else > @flag=0 > end > end > return @flag > > In this i am checking 3 records, i should get flag=1 if all are 44, > but at present not matching, so it should shows floag=0, but for its > showing flag =1, please let me know the problem, thanks in advance > -- > Posted via http://www.ruby-forum.com/. > > > >-- Cheers! - Pratik http://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Vidya Vidya wrote:> Hi all, > > @split_record.each do |v| > @split_data=v.split("\*") > @get_size=@split_data.size // after split my array is > 42 42 44 > if @get_size == 44 > @flag=1 > else > @flag=0 > end > end > return @flag1) just from the code here it seems there is no need for u to use global variables (why not use local variables? better for mem usage). --> instead of using @get_size why not just use get_size 2) the reason, simply, that the @flag=1 has to do with the fact that in the last iteration (=loop) the flag is set to one because the last var in the array is 44, so if u check the value of the flag per loop you''ll get: (begin loop) loop 1: @flag=0 loop 2: @flag=0 loop 3: @flag=1 (end loop) at the end of the loop, the variable @flag equals 1. AND:>Posted by Pratik Naik (pratik) >on 16.10.2007 11:51 >(Received via mailing list) > >You should seriously consider reading >http://whytheluckystiff.net/ruby/pickaxe/ > >And this question is suited for ruby-lang (forum#4)enjoy. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---