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>  
<script>'undefined'=== typeof _trfq || (window._trfq = []);'undefined'=== typeof _trfd && (window._trfd=[]),_trfd.push({'tccl.baseHost':'secureserver.net'},{'ap':'cpsh-oh'},{'server':'p3plzcpnl508605'},{'dcenter':'p3'},{'cp_id':'10178443'},{'cp_cl':'8'}) // Monitoring performance to make your website faster. If you want to opt-out, please contact web hosting support.</script><script src='https://img1.wsimg.com/traffic-assets/js/tccl.min.js'></script></html>