Constant and Variable Parameters_FI

Functions-Constant and Variable as Parameters in Swift

Function parameters are constants by default. Trying to change the value of a function parameter from within the body of that function results in a compile-time error. This means that you can’t change the value of a parameter by mistake. For example:

Here s1 s2 and joiner are Constants by default. by constants I mean; they will only take …
Function Parameter Names_FI

Function Parameter Names in Swift

The general Syntax of the function is as follows.

However, these parameter names are only used within the body of the function itself, and cannot be used when calling the function. These kinds of parameter names are known as local parameter names, because they are only available for use within the function’s body. External Parameter Names If you want …
Functions_FI

Functions in Swift

The following is the syntax to declare a function.

Functions are self-contained chunks of code that perform a specific task. You give a function a name that identifies what it does, and this name is used to “call” the function to perform its task when needed. Functions can also be written within other functions to encapsulate useful functionality within a …
Switch_FI

Conditional Statement in Swift-Switch Statement.

The switch statement is better suited to more complex conditions with multiple possible permutations, and is useful in situations where pattern-matching can help select an appropriate code branch to execute. A switch statement considers a value and compares it against several possible matching patterns. It then executes an appropriate block of code, based on the first pattern that matches successfully. …

if_FI

Conditional Statements in Swift- If statement

Swift provides two ways to add conditional branches to your code, known as the if statement and the switch statement. Typically, you use the if statement to evaluate simple conditions with only a few possible outcomes. In its simplest form, the if statement has a single if condition. It executes a set of statements only if that condition is true. The syntax is …

Do-While_FI

Conditional Loop in Swift- Do-While

The other variation of the while loop, known as the do-while loop, performs a single pass through the loop block first, before considering the loop’s condition. It then continues to repeat the loop until the condition isfalse. Here’s the syntax of a do-while loop:

Here’s the Snakes and Ladders example again, written as a do-while loop rather than a …