Hi guys,
I need some guidance on a code i wrote. I am trying to implement a sliding-window technique, in which I have to increment one "for" loop(dependent on the index of larger loop) within another "for" loop.
Now the code i have is
for ($i=$analysisstartposn-1 ; $i<($seqlength-$windowsize) ; $i+$steps +ize) { for ($j = $i ; $j < $i+$windowsize ; $j++) { print OUTFILE "$i\t$j\n"; } }
I use "strict" and "diagnostics" in my script and i get an error that says "useless use of addition (+) in void context at line #(where the for loop with $j is present in the above code)"
If i have a step-size of 2 and a window size of 4, the output i need has to be in the form of:
i j
0 0
0 1
0 2
0 3
2 2
2 3
2 4
2 5
......... and so on

but the output i get, from the above code is in a way that $i does not increase, only $j resets and then increases at the end of its loop. I mean its like this
i j
0 0
0 1
0 2
0 3
0 0
0 1
0 2
0 3
..... and so on

Any help would be appreciated
Thanks in advance

Krish

In reply to Incrementing one "for" loop within another "for" loop by krish28

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.