What is the WordPress loop?

The WordPress loop is a PHP code that retrieves and displays posts. It’s used in theme files to display content dynamically.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
<?php endwhile; endif; ?>