When working with loop logic in the WP Query, it’s important to reuse the built-in WP functions so that you won’t re-invent the wheel. Rather than writing your own function, by sticking to built-in ones will ensure the cleanliness of the code, bug-free and boost the overall performance.
Here are some of the WP functions I’ve used quite often in the WP projects.
$wp_query->found_posts
will give you the total number of posts in the loop.
get_query_var( 'posts_per_page' )
will give you the number of posts per page.
get_query_var( 'paged' )
will give you the current page number.
$wp_query->post_count
will give you the number of posts on the current page.