Skip to content

Flow and conditions

We have been focusing on sequence so far. With sequence, you can picture instructions flowing through the computer as it executes them one at a time.

Control flow is all about controlling that flow of instructions (hence the name - control flow). Each language has several control flow statements that define a certain flow pattern. Each of these patterns is controlled by a condition which evaluates to true of false - which is known as a boolean value.

Illustration of control flow

Example

using static SplashKitSDK.SplashKit;
using static System.Convert;
// You can create boolean variables to store true/false values.
// There are also keywords for true and false
bool ready = false;
Write("Enter a number: ");
string line = ReadLine();
int value = ToInt32(line);
// You can calculate boolean values using comparisons like this
bool bigValue = value > 100;
Write("Is that a big value for you? [y/n]: ");
line = ReadLine();
// You can join boolean values using logical operators
// It is big for the user if they entered 'y' or 'Y'
bool bigForUser = (line == "y") || (line == "Y");
// You can join any boolean value using the logical operators
bool bigForBoth = bigForUser && bigValue;