Making decisions by using the if statement
The most common way to make a decision in C++/CLI is to use the if statement. You can use the if
statement to perform a one-way test, a two-way test, a multiway test, or a nested test. Let’s consider
a simple one-way test first.
performing one-way tests
The following example shows how to define a one-way test in C++/CLI:
if (number < 0)
Console::WriteLine("The number is negative");
Console::WriteLine("The end");
The if keyword is followed by a conditional expression, which must be enclosed in parentheses. If
the conditional expression evaluates to true, the next statement is executed, which in this example
will display the message “The number is negative”. Notice that the message “The end” will always be
displayed, regardless of the outcome of the test, because it is outside the body of the if statement.
Do'stlaringiz bilan baham: |