戻る

ループ処理(while文)

JavaScript

<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
var x = 0;
var str = "";

while(x < 5){
	str += String(x);
	document.getElementsByTagName("body")[0].innerHTML = str;
	
	x++;
}
</script>
</html>

01234

PHP

<?php
header("Content-type: text/plain; charset=utf-8");

$x = 0;

while($x < 5){
	echo $x;
	$x++;
}
?>

01234

<?php
header("Content-type: text/plain; charset=utf-8");

$x = 0;

while($x < 5):
	echo $x;
	$x++;
endwhile;
?>

01234

例:

<?php
header("Content-type: text/html; charset=utf-8");

$kensu = 0;
?>
<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?while($kensu < 5):?>
	<article>
		<header>…タイトル…</header>
		<section>
		…記事…
		</section>
		</footer>…投稿日…</footer>
	</article>
<?$kensu++?>
<?endwhile;?>
</body>
</html>

inserted by FC2 system