Last active
August 8, 2021 09:47
-
-
Save Gabbrolee/c0f0288df7c9a23d5a08615d44eb7f7a to your computer and use it in GitHub Desktop.
dayTwo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
//MARKS:- DICTIONARIES This is can be compare with an array in the sense that, it uses keys to address position of element in a collection but array uses index to access the position of element in a collection | |
var person = ["first":"Kemi", "second":"Bola", "last":"Temi", "month":"December", "website":"www.google.com"] | |
person["first"] // output: Kemi | |
person["month"] // output: December | |
//MARkS:- from the output above the key is first and the value is Kemi | |
// dictionaries use keys and values unlike array that use index to search | |
// for position of items in a collection | |
// ["key": "value" ] which can be in the form of [string: string], [Int: string] | |
//MARKS:- CONDITIONAL STATEMENTS | |
// Sometimes we want codes perform operation if a condition is true | |
// execute another line of code if it is false | |
// this can be handle by the conditional statement with if else | |
// if(code is true){perform this action} else {perform this action} | |
var age = 25 | |
var name = "Shayo" | |
if age == 25 { | |
print("Shayo is \(age) years old") | |
}else { | |
print("the if condition is false") | |
} | |
// since the if statement is true then its statement is printed | |
if age == 20 { | |
print("Shayo is \(age) years old") | |
} else { | |
print("The if condition is false so I am out") | |
} | |
// the if statements goes on like that as if.. elseif ..else | |
// this continue to happen until one of the condition is meant | |
// the statement of the condition meant is finally executed | |
// if none of the condition is satisfy, the else statement will be executed | |
//MARKS:- LOOPS | |
//This is use to perform iteration i.e number of times of operation needed | |
//1. for loop | |
for i in 1...10{ | |
print("God is good") // this will print the statement 10 times with count from 1 | |
} | |
var str = "Fakers gonna " // assign string to variable str | |
for i in 1...4{ // count from 1 to 4 | |
str += " fake" // add fake 4 times to str | |
} | |
print(str) // Fakers gonna fake fake fake fake | |
var people = ["players", "haters", "heartbreakers", "baby"] | |
var action = ["play", "hates", "break", "cry"] | |
for index in 0...2{ // this perform the operation 3 times with count | |
// from zero to 2 | |
print("\(people[index]) gonna \(action[index])") // index of array of people is printed at same index | |
// of that of action | |
} | |
// the total element in the array can be known with the use of count property | |
//people.count will give 3 | |
//but to get the last index we do people.count - 1 we get 2 | |
// you can put loops inside loop | |
for i in 0 ..< people.count{ // the loop goes 4 times | |
for i in 1...3 { // the loop goes 3 times | |
print("\(people[i]) gonna \(action[i])") // total of 12 times | |
} | |
} | |
//MARKS:- When we dont know the number of | |
//count an operation will happen we use while loop | |
var counter = 0 | |
var sum = 0 | |
while true { | |
print("counter is now: \(counter)") | |
counter += 1 // inctement counter | |
if counter == 6 { // stop when it is 6 | |
break | |
} | |
sum += counter // continue adding the value of counter into sum | |
} | |
var songs = ["woo", "baby girl", "loadinginging"] | |
for song in songs { | |
if song == "baby girl"{ | |
continue | |
} | |
print("my favorite song is \(song)") | |
} | |
//MARKS:- SWITCH CASE | |
// this test the block of variable one is looking | |
//for and once it is found it execute and stop | |
// it ensures the case are exhaustive | |
//otherwise xcode wont compile | |
let liveAlbums = 2 | |
switch liveAlbums { | |
case 0: | |
"lets go to Dubai" | |
case 1: | |
"where are you" | |
case 2: | |
"this will be executed" | |
default: | |
"this is a default incase the search is not found" | |
} | |
// case range operator can also be use as well 0...2 | |
//MARKS:- FUNCTIONS | |
func getOut(){ // function without parameter | |
print("lets go home if you don't mind") | |
} | |
getOut() // function call | |
func getOutNow(name:String){ | |
print("lets go home if you don't mind \(name)") | |
} | |
getOutNow(name: "Samuel") | |
func albumRelease(name:String, year: Int){ | |
print("\(name) is release in \(year)") | |
} | |
albumRelease(name: "BOO" , year: 2010) | |
func getMeal(_ food: String) -> Bool { | |
if food == "rice" { | |
true | |
} | |
else if food == "beans" { | |
return true | |
}else { | |
return false | |
} | |
return ( 0 != 0) | |
} | |
getMeal( "yam") |
Author
Gabbrolee
commented
Aug 5, 2021
via email
will try it out today... thanks much sir....I will need to explain code
snippet on another platform then make a short comment on GitHub
…On Thu, 5 Aug 2021, 10:47 Waheed Afolabi, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
line 3 repeated one of things I tried to correct from the first day
submission.
Don't allow a sentence to be too long, it's not palatable for reading.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/c0f0288df7c9a23d5a08615d44eb7f7a#gistcomment-3846465>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUFQTP4Z36SDIOHNMYJWFLLT3JM4RANCNFSM5BTPVEEQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
Yes I did would have noted it down before sending it...like it skip my mind
…On Thu, 5 Aug 2021, 10:52 Waheed Afolabi, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Did you check the sample gist in the DayOne comment of yesterday?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/c0f0288df7c9a23d5a08615d44eb7f7a#gistcomment-3846479>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUFQTP3FMG52SYCEC72SZGDT3JNPFANCNFSM5BTPVEEQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment