Conditions
Conditions
Conditions is a free Swift Academy lesson on CoddyKit — lesson 1 of 1. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 1 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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")if-else statement
In some cases, we may need some codes to work for situations where the if condition is not met.
An if-else statement is used for this. Let's find out with an example.
var age = 10
if age > 100 {
print("if age is greater than 100")
} else {
print("Works when the age is less than 100")
}
switch-case
switch-case Statement
In some cases, we may want to control the fulfillment of multiple conditions with a single block of code. Even though we can use multiple if-else statements in such cases, the easier and more logical one is swift-case.
The example below contains a switch-case statement that works for 5 different conditions.
let someNumber = 150
switch someNumber {
case 50:
print("Number is 50")
case 100:
print("Number is 100")
case 150:
print("Number is 150")
case 200:
print("Number is 200")
case 250:
print("Number is 250")
default:
//If none of them meet the requirement then the default block will work.
print("Otherwise, do something else.")
}Congratulations
Congratulations 🎉
In this lesson, we learned how to use conditional statements in Swift.
See you in the next lesson.

Frequently asked questions
Is the “Conditions” lesson free?
Yes — the full text of “Conditions” is free to read here on the web, and the Swift Academy course includes 1 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.
What will I learn in “Conditions”?
Conditions You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 1, so you can start here or from the beginning and move at your own pace.
How long does the “Conditions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.