PHP Version
4+
$i = 1;

while ($i <= 5) {
	echo $i . ' ';
	$i++;
}
// Output: 1 2 3 4 5
while (condition) {
    // Code block to execute
}
<?php while (condition): ?>
    <?php // Code block to execute ?>
<?php endwhile; ?>
<?php $i = 1; ?>
<?php while ($i <= 5): ?>
    <?php
        echo $i . ' ';
        $i++;
    ?>
<?php endwhile; // // Output: 1 2 3 4 5 ?>
// Database connection settings
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create a database connection using MySQLi
$conn = new mysqli($servername, $username, $password, $dbname);

// Check the connection status
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query to retrieve the list of posts
$sql = "SELECT id, title, content FROM board";
$result = $conn->query($sql);

// Process the result
if ($result) {
    if ($result->num_rows > 0) {
        // Use the while statement to display all posts
        while ($row = $result->fetch_assoc()) {
            echo "ID: " . $row["id"] . " - Title: " . $row["title"] . " - Content: " . $row["content"] . "<br>";
        }
    } else {
        echo "No posts found.";
    }
} else {
    echo "Query error: " . $conn->error;
}

// Close the database connection
$conn->close();
$i = 1;

while ($i <= 5) {
	echo $i;
	/* Without the increment/decrement expression in this code, an infinite loop occurs. */
	//$i++;
}