Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to limit the number of "forech" outputs?
#1
I would like to limit the output to only five of the lists included in the variable"s".

What should I do if I want to do "BREAK" after I output the 5 lists?

I'd like to know how to solve it.


Ex:
ARRAY(str) a="1[]2[]3[]4[]5[]6[]7[]8[]9[]10"
int i
for(i 0 a.len)
    if(i=5) break
    out a[i]


out

str s=
;c:\program files\myexe1.exe
;c:\program files\myexe2.exe
;c:\program files\myexe3.exe
;c:\program files\myexe4.exe
;c:\program files\myexe5.exe
;c:\program files\myexe6.exe
;c:\program files\myexe7.exe
;c:\program files\myexe8.exe
;c:\program files\myexe9.exe
;c:\program files\anotherone.exe

str sw=
;myexe1
;mystuff
;anotherone
;somethingelse

sub.Included_Words s sw _s
out _s
#sub Included_Words
function str&Word_list str&Included_Words str&outlist


ARRAY(str) am au AM AU
foreach _s Included_Words
,if(find(Word_list _s 0 1)<0) au[]=_s
,else am[]=_s

foreach _s Word_list
,for(_i 0 am.len)
,,if(find(_s am[_i] 0 1)>=0) break
,if(_i<am.len)
,,AM[]=_s;
,,outlist.addline(_s 1)
,else
,,AU[]=_s
#2
not completely sure on what your asking but try this

Code:
Copy      Help
out

str s=
;c:\program files\myexe1.exe
;c:\program files\myexe2.exe
;c:\program files\myexe3.exe
;c:\program files\myexe4.exe
;c:\program files\myexe5.exe
;c:\program files\myexe6.exe
;c:\program files\myexe7.exe
;c:\program files\myexe8.exe
;c:\program files\myexe9.exe
;c:\program files\anotherone.exe

str sw=
;myexe
;mystuff
;anotherone
;somethingelse

sub.Included_Words s sw _s
,out _s

#sub Included_Words
function str&Word_list str&Included_Words str&outlist


ARRAY(str) am au AM AU
foreach _s Included_Words
,if(find(Word_list _s 0 1)<0) au[]=_s
,else am[]=_s

foreach _s Word_list
,for(_i 0 am.len)
,,if(find(_s am[_i] 0 1)>=0) break
,if(_i<am.len)
,,AM[]=_s;
,,if(numlines(outlist) <5)
,,,outlist.addline(_s 1)
,else
,,AU[]=_s
#3
Thank you for your help.
That's what I wanted.
#4
could also:
- use a counter variable that gets incremented only under the condition that a value is added to the array. If counter >= 5; break
- instead of checking numlines of outlist, could also check length of ARRAY(str). if AM.len >= 5; break


Forum Jump:


Users browsing this thread: 1 Guest(s)