课程: Complete Guide to C Programming Foundations

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Exploring the possibilities

Exploring the possibilities

- [Instructor] The if keywords companion is the else keyword. Combined, you use if and else in your code to create blocks of either/or decisions. For example, in this code, input is obtained from the user. The if statement at line 11 tests to see whether the value of variable A is greater than the value of variable B. If true, the statement belonging to if is executed. Otherwise, the else statement is executed. I'll try a few values, 10 and 20, and 20 is greater than 10, eight is greater than negative one, and now I'm going to try the same value. Well, the program didn't error, it just did what you told it to do. In the code, the else statement catches all conditions where A is greater than B is false, including when A is equal to B. To address this situation, we can modify line 13 to better reflect this result. Change it into an else/if statement. B is greater than A. This construction is a combination of else and if, and it represents a second decision. When this condition is true…

内容