Source Code

Chess Board using Nested For Loop

PHP for loops Exercise: Create a table using for loop

Write a PHP script using nested for loop that creates a chess board as shown below.

Example : index.php


<!DOCTYPE html>  
<html>   
<head>   
<title></title>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
</head>  
<body>   
<h3>Chess Board using Nested For Loop</h3>  
<table width="270px" cellspacing="0px" cellpadding="0px" border="1px">  
<tr><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td></tr><tr><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td></tr><tr><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td></tr><tr><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td></tr><tr><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td></tr><tr><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td></tr><tr><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td></tr><tr><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td><td height=30px width=30px bgcolor=#000000></td><td height=30px width=30px bgcolor=#FFFFFF></td></tr>  
</table>  
</body>  
</html>