반응형
<!doctype html>
<html>
<head>
</head>
<body>
<table border="1" width="150">
<?php
$i=1;
$val = 0;
echo "<tr><th colspan=\"2\">2단</th></tr>";
/*1부터 9까지 반복*/
while($i<10){
$val = 2*$i;
echo "<tr><th>2* $i </th><td> $val </td>";
$i++;
}
?>
</table>
</body>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<?php
$j=2;
while($j<10){ //단수증가
$i=1;
$val = 0;
echo '<table border="1" width="150">';
echo "<tr><th colspan=\"2\"> $j 단</th></tr>";
/*1부터 9까지 반복*/
while($i<10){ //곱셈식 반복
$val = $j*$i;
echo "<tr><th>$j * $i </th><td> $val </td>";
$i++;
}
echo '</table>';
$j++;
}
?>
</body>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<?php
/*while문*/
$j=2;
while($j<10){ //단수증가
echo "$j";
$j++;
}
/*for문*/
for($j=2;$j<10;$j++){
echo "$j";
}
for($j=2;$j<10;$j++){
$val = 0;
echo '<table border="1" width="150">';
echo "<tr><th colspan=\"2\"> $j 단</th></tr>";
/*1부터 9까지 반복*/
for($i=1;$i<10;$i++){ //곱셈식 반복
$val = $j*$i;
echo "<tr><th>$j * $i </th><td> $val </td>";
}
echo '</table>';
}
?>
</body>
</html>
반응형
댓글