find out if it is the last iteration of the for loop c++

#include <iostream>

int main() {
    int n = 10; // Set the loop limit

    for (int i = 0; i < n; ++i) {
        // Loop body

        if (i == n - 1) {
            // Check if it is the last iteration
            std::cout << "This is the last iteration of the loop." << std::endl;
        } else {
            std::cout << "Not the last iteration." << std::endl;
        }
    }

    return 0;
}