Question

Answers

  • user image
    Anurag Srivastava
    Sep 22, 2020, 5:01:17 PM |

    For a chessboard, we need to draw  64 boxes (8 rows and 8 columns) let us plan how we should proceed.

    • We should run two loops to create the 64 boxes.
    • The outer loop should run 8 times.
    • The inner loop should also run 8 times. So for each outer loop iteration, the inner loop will run 8 times.

    Now I am giving a code example in PHP, hope this will help you to understand the logic:

    <table border = '2'>
    <?php
    for($i=1; $i<9;$i++)
    {
        ?> <tr> <?php
        for($j=1; $j<9; $j++)
        {
            $total = $i+$j;
            if($total%2 == 0)
            {
                ?> <td style="background-color: black;" width = 80px; height = 80px;> </td><?php
            }
            else
            {
                ?> <td width = 80px; height = 80px;> </td><?php
            }
            
        }
        ?> </tr> <?php
    }
    ?>
    </table>
    Let me know if you have any further queries.

    0 | 0


Related Blogs

preview thumbnail
Introduction to Kibana

Aug 1, 2020, 6:19:45 PM | Anurag Srivastava

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava

preview thumbnail
Introduction to Elasticsearch Aggregations

Aug 14, 2018, 4:47:56 PM | Anurag Srivastava

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

preview thumbnail
Basics of Data Search in Elasticsearch

Aug 4, 2018, 7:02:21 AM | Anurag Srivastava

Top Blogs

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

preview thumbnail
Elasticsearch REST APIs

Jul 31, 2018, 6:16:42 PM | Anurag Srivastava

preview thumbnail
preview thumbnail
Create a Chess board in PHP

Mar 9, 2020, 8:45:41 AM | Rocky Paul

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava