Announcement

Collapse
No announcement yet.

while loop question....

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Goldfinger
    replied
    Originally posted by Zzed
    You can also remove the = from the while loop.

    PHP Code:
    echo "$number is number<BR>";

    $t 0;
    while (
    $t "$number") {
    $estimate[$t] = ($width[$t] + $length[$t]);
    $temp $t 1;
    echo 
    "<BR>$estimate[$t] is estimate $temp<BR>";
    $t++;


    um.. that was for less than or equal to. the way he did it before was the correct way. your for loop is..

    4 is number

    0 is estimate 1

    0 is estimate 2

    0 is estimate 3

    0 is estimate 4

    Leave a comment:


  • Zzed
    replied
    You can also remove the = from the while loop.

    PHP Code:
    echo "$number is number<BR>";

    $t 0;
    while (
    $t "$number") {
    $estimate[$t] = ($width[$t] + $length[$t]);
    $temp $t 1;
    echo 
    "<BR>$estimate[$t] is estimate $temp<BR>";
    $t++;

    Leave a comment:


  • Tim Mousel
    replied
    I've got it working...I changed it to a for loop:


    PHP Code:
    echo "$number is number<BR>";

    for(
    $t=0$t<= ($number 1); $t++) {
    $estimate[$t] = ($width[$t] + $length[$t]);
    $temp $t 1;
    echo 
    "<BR>$estimate[$t] is estimate $temp<BR>";

    If there's a better way of doing this, please let me know.

    Thanks,

    Tim

    Leave a comment:


  • Tim Mousel
    replied
    Hi,

    Partially, here's the result:

    4 is number

    18 is estimate 1

    132 is estimate 2

    48 is estimate 3

    60 is estimate 4

    0 is estimate 5

    It's showing 0 for estimate 5 when there is no number 5.

    Any other solutions?

    Leave a comment:


  • Zzed
    replied
    Would this work?

    PHP Code:
    echo "$number is number<BR>";

    $t 0;
    while (
    $t <= "$number") {
    $estimate[$t] = ($width[$t] + $length[$t]);
    $temp $t 1;
    echo 
    "<BR>$estimate[$t] is estimate $temp<BR>";
    $t++;

    Leave a comment:


  • Tim Mousel
    started a topic while loop question....

    while loop question....

    Hi,

    I have a question about a while loop:

    PHP Code:
    echo "$number is number<BR>";

    $t 0;
    while (
    $t <= "$number") {
    $estimate[$t] = ($width[$t] + $length[$t]);
    echo 
    "<BR>$estimate[$t] is estimate $t<BR>";
    $t++;

    If $number is set to 4 I get the following for my output:

    4 is number

    18 is estimate 0

    12 is estimate 1

    24 is estimate 2

    24 is estimate 3

    0 is estimate 4


    How do I change my code to make it say:

    4 is number

    18 is estimate 1

    12 is estimate 2

    24 is estimate 3

    24 is estimate 4

    //0 is estimate 4


    Thanks!

    Tim
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X