|
Here is a more efficient way of doing this by using a nested if statement:
|
This version is more efficient than the first one. If the Leafs win then only one comparison is needed. The Leafs won!!! will be printed and the rest of the nested if will be skipped. If the Leafs lose then two comparisons will be needed and the else part will be skipped. If the Leafs tie then there will still only be two comparisons. The first example always needed three comparisons.
Here is another example using nested if statements:
|
|
|