Complex decisions are handled in C by using an if-else structure, as well as a more complex series of if-else-if-else statements. Program control can be altered based on a decision, where multiple outcomes are possible.
- 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 twice. … 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, … but if not, the else statement is executed instead. … Build and run the code. … Let's try a few values. … 10 and 20, 20 is greater than 10. … Glad the computer knows this. … It's run again, and we'll try eight and negative one … and eight is greater than negative one. … We're going to run it one more time and try the same value. … Hmm, the program didn't air. … It did just what you told it to, … the else statement catches all conditions where A … is greater than B is false, including when A is equal to B. … This code addresses the issue with the proceeding example … by adding an else if statement at line 13. … This construction is a combination of else and if, …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.