Game Development Reference
In-Depth Information
Listing 6-3. The else if Statement
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
if (false)
{
cout << "Print This When True!";
}
else if (true)
{
cout << "Print This When Else If Is True!";
}
else
{
cout << "Print This If All False!";
}
return 0;
}
Here you can see that the extra else if statement will cause the code to execute its block and miss
the else block. Listing 6-4 shows that we can have multiple else if blocks.
Listing 6-4. Multiple else if Blocks
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
if (false)
{
cout << "Print This When True!";
}
else if (false)
{
cout << "Print This When First Else If Is True!";
}
else if (true)
{
cout << "Print This When Second Else If Is True!";
}
Search WWH ::




Custom Search