Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if statement used without braces in the PagingProducts() method on page 518 #67

Open
MAS-OUD opened this issue May 4, 2023 · 0 comments

Comments

@MAS-OUD
Copy link
Contributor

MAS-OUD commented May 4, 2023

On page 518, the if statement in the method PagingProducts() is used without braces:

if (key == ConsoleKey.LeftArrow)
    if (currentPage == 0)
        currentPage = totalPages;
    else
        currentPage--;
else if (key == ConsoleKey.RightArrow)
    if (currentPage == totalPages)
        currentPage = 0;
    else
        currentPage++;
else
    break; // out of the while loop.

I think it should be written with braces:

if (key == ConsoleKey.LeftArrow)
{
    if (currentPage == 0)
    {
        currentPage = totalPages;
    }
    else
    {
        currentPage--;
    }
}
else if (key == ConsoleKey.RightArrow)
{
    if (currentPage == totalPages)
    {
        currentPage = 0;
    }
    else
    {
        currentPage++;
    }
}
else
{
    break; // out of the while loop.
}

Or in the more concise form:

if (key == ConsoleKey.LeftArrow)
{
    currentPage = (currentPage == 0) ? totalPages : currentPage - 1;
}
else if (key == ConsoleKey.RightArrow)
{
    currentPage = (currentPage == totalPages) ? 0 : currentPage + 1;
}
else
{
    break; // out of the while loop.
}
@MAS-OUD MAS-OUD changed the title if statement without braces in the PagingProducts() method on page 518 if statement used without braces in the PagingProducts() method on page 518 May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant