This resource is designed as a quick reference or revision guide. It has not been endorsed by any exam boards. If you spot any mistakes, please let me know and I'll fix them asap.
Logic is the ability to make decisions. Conditional logic means making decisions based on clearly defined conditions, e.g. If the starting gun for a race has been fired then start running, else (otherwise) keep waiting.
You can compare data using the greater than > operator or the less than < operator.
In VB.NET you use one equals sign (=) to both set a value and test if two values are the same.
In python you use one equals sign (=) to set a value and two equals signs to test if two values are the same.
If you want your code to make a decision you'll need an IF statement.
This example asks the user how old they are and checks that they've entered a number bigger than 0
If you want your code to choose between two possibilities you'll need an IF ... ELSE statement.
This example asks the user what their name is. If they answer the question it says hello. If they don't answer the question it displays an error message.
You can test if two expressions are the same using the equal to or not equal to operator.
An expression can be a variable or combination of variables & data (e.g. 1 + 1)
An operator is a symbol that means add, subtract or something similar.
This example asks the user to enter a temperature of a bath (in degrees Celsius) and then follows the following rules:
Equal to 37 degrees: says "Perfect - that's body temperature"
Not equal to 37 degrees: "Not body temperature"
If you need to compare two expressions you will need the greater than or less than operators.
An expression can be a variable or combination of variables & data (e.g. 1 + 1)
An operator is a symbol that means add, subtract or something similar.
This example asks the user to enter a password and displays how strong that password is based purely on the length:
Less than 5 characters: weak
More than or equal to 8 characters: strong
Otherwise: medium
Loading...