Conditions
Conditions
Introduction
Hello,
In this lesson, we will learn about the conditional concept, which is a must for programming languages.
The first thing we will learn is if statement. With the if statement, we can run a block of code depending on the occurrence of a condition.
In the example below, the syntax of the if statement has been added.
The part expressed by conditional_expression is an expression that returns a bool value. If this expression returns true, the block of code between braces will work.
if conditional_expression {
/* set of statements */
}
example
Suppose we have a number named count. If the value of this number is greater than 20 we will print the 'Yes, count is greater than 20' text
var count:Int = 20
if count > 20 {
print("Yes, count is greater than 20")
}
print("always work")