OnWorks Linux and Windows Online WorkStations


Free Hosting Online for WorkStations

< Previous | Contents | Next >

27 – Flow Control: Branching With if‌

In the last chapter, we were presented with a problem. How can we make our report-gen- erator script adapt to the privileges of the user running the script? The solution to this problem will require us to find a way to “change directions” within our script, based on the results of a test. In programming terms, we need the program to branch.

Let’s consider a simple example of logic expressed in pseudocode, a simulation of a com- puter language intended for human consumption:

X = 5

If X = 5, then:

Say “X equals 5.” Otherwise:

Say “X is not equal to 5.”

This is an example of a branch. Based on the condition, “Does X = 5?” do one thing, “Say X equals 5,” otherwise do another thing, “Say X is not equal to 5.”


Top OS Cloud Computing at OnWorks: