2. Directing Program Flow

This chapter is all about taking control of your code by making programs flow as you want. You’ll see how to make choices with the if statement, loop over and over with loops, and more.

The primary program flow statement that allows you to make choices is the if statement. With the if statement, you can test a condition and execute code depending on whether or not the statement is true. For example, say you have a variable named temperature, which is set to 72:

#include <stdio.h>int main(void){  int temperature = 72;       .       .       .}

You can use the == equality operator to test whether the value of the temperature variable is equal to 72 and, if so, execute specific code like this:

#include <stdio.h>int main(void) ...

Get Objective-C: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.