简体   繁体   中英

How inner if condition is executed evebn when the outer if is false for i=1 and v=4

1 how inner if condition is working when the outer if condition is false for i=1 and v=4.

if (i == V) {
        // if coloring is safe
        if (isSafe(graph, color)) {
            // Print the solution
            printSolution(color);
            return true;
        }
        return false;
    }

refer this program for complete code

https://ide.geeksforgeeks.org/AfK9JFN2aD

2 can someone plz explain how code is working?how each node is assigned a new colour. https://ide.geeksforgeeks.org/AfK9JFN2aD

if (i == V)
{
    // if coloring is safe
    if (isSafe(graph, color))
    {
        // Print the solution
        printSolution(color);
        return true;
    }
    return false;
}

This is equivalent to:

if (i == V) goto FIRST_IF_START;
else        goto FIRST_IF_END;

FIRST_IF_START:
{
    // if coloring is safe
    if (isSafe(graph, color)) goto SECOND_IF_START;
    else                      goto SECOND_IF_END;

    SECOND_IF_START:
    {
        // Print the solution
        printSolution(color);
        return true;
    }
    SECOND_IF_END:
    return false;
}
FIRST_IF_END:

I hope this better illustrates how an if works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM