0
0
Swiftprogramming~15 mins

Semicolons are optional behavior in Swift - Mini Project: Build & Apply

Choose your learning style9 modes available
Semicolons are optional behavior
📖 Scenario: Imagine you are writing a simple Swift program to greet friends. Swift allows you to write code with or without semicolons at the end of each statement. This project will help you understand how semicolons work in Swift.
🎯 Goal: You will create a small Swift program that prints greetings to friends using semicolons optionally. You will see how semicolons can be used or omitted without changing the program's behavior.
📋 What You'll Learn
Create a variable with a friend's name
Create a variable with another friend's name
Print greetings to both friends using semicolons at the end of statements
Print greetings to both friends without semicolons at the end of statements
💡 Why This Matters
🌍 Real World
Knowing that semicolons are optional helps you read Swift code written by others and write your own code in a style you prefer.
💼 Career
Swift developers often write clean code without semicolons, but understanding them is important for reading legacy code or code from other languages.
Progress0 / 4 steps
1
Create variables with friend names
Create two variables called friend1 and friend2 with the exact values "Alice" and "Bob" respectively.
Swift
Need a hint?

Use var to create variables and assign the exact string values.

2
Add semicolons to print greetings
Add two print statements to greet friend1 and friend2 using semicolons at the end of each statement. Use print("Hello, \(friend1)!"); and print("Hello, \(friend2)!"); exactly.
Swift
Need a hint?

Remember to put a semicolon ; at the end of each print statement.

3
Rewrite print statements without semicolons
Rewrite the two print statements to greet friend1 and friend2 exactly as before but without semicolons at the end of each statement.
Swift
Need a hint?

Simply remove the semicolons at the end of each print statement.

4
Print all greetings to show output
Add print statements to display greetings to friend1 and friend2 exactly as Hello, Alice! and Hello, Bob! without semicolons. This will show the program output.
Swift
Need a hint?

Use print statements to show the greetings exactly as output.