Hello,

Consider the following code:

start=1.6; for($inc=.1;$inc<=.9;$inc=$inc+.1{ #print"\nThe value of inc:"; #print"\n$inc"; $start_pt=$start+$inc; #print"\nThe value of start_pt :"; #print"\n$start_pt"; + SWITCH: {if ($start_pt==2) {$start_pt=$start_pt-.9; last SWITCH;} if($start_pt==2.1){$start_pt=$start_pt-.99; last SWITCH;} if($start_pt==2.2){$start_pt=$start_pt-1.08;last SWITCH;} if($start_pt==2.3){$start_pt=$start_pt-1.17;last SWITCH;} if($start_pt==2.4){$start_pt=$start_pt-1.26;last SWITCH;} if($start_pt==2.5){$start_pt=$start_pt-1.35;last SWITCH;} $nothing = 1; } #print"\nThe value of start_pt :"; #print"\n$start_pt"; SWITCH: {if ($start_pt==1.7) {$end_pt=1.8; last SWITCH;} if($start_pt==1.8) {$end_pt=1.9; last SWITCH;} if($start_pt==1.9) {$end_pt=1.10; last SWITCH;} if($start_pt==1.10){$end_pt=1.11; last SWITCH;} if($start_pt==1.11){$end_pt=1.12; last SWITCH;} if($start_pt==1.12){$end_pt=1.13; last SWITCH;} if($start_pt==1.13){$end_pt=1.14; last SWITCH;} if($start_pt==1.14){$end_pt=1.15; last SWITCH;} $nothing = 1; } print"\nThe value of end_pt :"; print"\n$end_pt"; }


The first time the value of $start_pt is printed we get
th foll.values:

1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5

When we print the value of $start_pt after the first switch
statement we get:

1.7 1.8 1.9 1.1 1.11 1.12 1.13 1.14 1.15
For the value 1.1 of $start_pt is it possible to have this
value read as 1.10 and not truncated to 1.1.Actually I
need to use these values as text indices in a Tk text
widget.The 1.10 means the 10th char on the first
line.If this value is read as 1.1, this would mean 1st
char on 1st line, which is not what is required.

Also the values of end_pt are printing as:
1.9 1.9 1.11 1.12 1.13 1.14 1.15 1.15

whereas these are the values that need to be printed:
1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15

What is the mistake here?
Thanx.

In reply to Simple loop question by perl_seeker

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.