Jump to content

plzzzzzz help in formatted output


antonyjohn

Recommended Posts

There is undoubtedly a prettier solution than this. But here you go. Modify 5 to make it grow bigger and stuff. Probably better idea to put it in a variable. Enjoy.

 

    $count_up = true;
    $i = 1;
    while($i<5 && $i!=0)
    {
      $j = 0;
      while($j<$i)
      {
        echo ($j+1);
        ++$j;
      }
      echo "<br />";
      
      if( $count_up )
      {
        if(($i+1) != 5)
        { 
          ++$i; 
        }
        else
        {
          --$i;
          $count_up = false;
        }
      }
      else
      {
        --$i;
      }
    }

$max = 20;

for($x=1; $x<=$max; $x++) {

    for($y=1; $y<=$x; $y++) {

        print $y;

    }

    print "\n";

}

for($x=$max-1; $x>=1; $x--) {

    for($y=1; $y<=$x; $y++) {

        print $y;

    }

    print "\n";

}

 

New Modified

 

 

<?php
$start = 1;
$end = 4;
$main_loop = $start + ($end-$start)*2+1;
$status = "forward";
for($i=$start;$i<=$main_loop;$i++){
if($status == "forward"){
	$to = $i;
}elseif($status == "backword"){
	$to = $to - 1;
}
for($j=$start;$j<=$to;$j++){
	echo $j;
}
echo "<br>";
if($i == $end){
	$status = "backword";
}
}
?>

;)

  while( ($dest = 4) && !isset($b) && (($b = ($max = $dest * ($i = $j = 1) + 1) < 0) == false) ) 
    while ((!$b && $i < ($max + ($j = 0))) || ($b && ($i-- > 0 + ($j = 0))) )
      while( (($j < $i ? ++$j : $max + (!$b ? ++$i : (5 + $i)) ) <= $max && print($j))  
          || !print("<br />".(($b = $b || ($i == $max)) ? (($i = ($i == $max ? $i - 1 : $i)) ? '' : '') : ''))
      ) ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.