-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sohilladhani/dev
Update master branch
- Loading branch information
Showing
48 changed files
with
1,646 additions
and
203 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#https://stackoverflow.com/q/43667176 | ||
|
||
# Generated files | ||
/target/ | ||
|
||
# The library shouldn't decide about the exact versions of | ||
# its dependencies, but let the downstream crate decide. | ||
#Cargo.lock |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#https://stackoverflow.com/q/43667176 | ||
|
||
# Generated files | ||
/target/ | ||
|
||
# The library shouldn't decide about the exact versions of | ||
# its dependencies, but let the downstream crate decide. | ||
Cargo.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "control_flow" | ||
version = "0.1.0" | ||
authors = ["Sohil Ladhani <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
fn main() { | ||
let num = 3; | ||
|
||
/* good ol' if-else */ | ||
if num < 5 { | ||
println!("num is less than 5"); | ||
} else { | ||
println!("num is not less than 5"); | ||
} | ||
|
||
/* The condition must always be 'bool' otherwise rust will throw error */ | ||
/*if num { | ||
println!("num is 3"); | ||
}*/ | ||
/* shadowing of 'num' variable */ | ||
let num = 7; | ||
|
||
if num % 4 == 0 { | ||
println!("num is divisible by 4"); | ||
} else if num % 3 == 0 { | ||
println!("num is divisible by 3"); | ||
} else if num % 2 == 0 { | ||
println!("num is divisible by 2"); | ||
} else { | ||
println!("num is not divisible by 4,3,2"); | ||
} | ||
|
||
/* We can use if on the right side of the if statement | ||
* Meaning a variable is assigned a value if the condition holds*/ | ||
|
||
let condition = true; | ||
let number = if condition { | ||
5 | ||
} else { | ||
6 | ||
}; | ||
|
||
println!("The value of number is: {}", number); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#https://stackoverflow.com/q/43667176 | ||
|
||
# Generated files | ||
/target/ | ||
|
||
# The library shouldn't decide about the exact versions of | ||
# its dependencies, but let the downstream crate decide. | ||
#Cargo.lock |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "data_types" | ||
version = "0.1.0" | ||
authors = ["Sohil Ladhani <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
fn main() { | ||
|
||
/* There are 2 kinds of data types */ | ||
/* 1. Scalar Types 2. Compound Types */ | ||
|
||
/* 1. Scalar Types */ | ||
/* There are 4 types of scalar types */ | ||
|
||
/* i. Integer type */ | ||
/* Variants: | ||
* i8, u8 | ||
* i16, u16 | ||
* i32 (default), u32 | ||
* i64, u64 | ||
* isize, usize */ | ||
let integer: u32 = 250; | ||
println!("The integer value is {}", integer); | ||
|
||
/* ii. Floating type */ | ||
/* Variants: | ||
* f32, f64 (default) */ | ||
let float: f64 = 3.5; | ||
println!("The float value is {}", float); | ||
|
||
/* iii. Boolean type */ | ||
/* true or false */ | ||
let true_value = true; | ||
let false_value: bool = false; // with explicit type annotation | ||
println!("Does the Earth rotate around the Sun?: {}", true_value); | ||
println!("Is the Earth flat?: {}", false_value); | ||
|
||
/* iv. Character */ | ||
let c = 'c'; | ||
let z = '\u{2602}'; | ||
println!("Characters: {} {}", c, z); | ||
|
||
/* 2. Compound Types */ | ||
|
||
/* i. Tuples */ | ||
/* A tuple is a general way of grouping together some number of other | ||
* values with a variety of types (heterogeneous elements) | ||
* into one compound type */ | ||
let tup: (i32, f64, u8) = (1992, 6.0, 2); | ||
|
||
/* To get the individual values out of a tuple, we can use pattern | ||
* matching to "destructure" a tuple value, like this: */ | ||
let (y, m, d) = tup; | ||
println!("DOB is: {}-{}-{}", y, m, d); | ||
|
||
/* Another way to access elements of a tuple */ | ||
let year = tup.0; | ||
let month = tup.1; | ||
let date = tup.2; | ||
println!("DOB is: {}-{}-{}", year, month, date); | ||
|
||
/* ii. Arrays */ | ||
/* Arrays are a way to group homogeneous elements. i.e. Each element | ||
* in an array is of same type. | ||
* Arrays in Rust have fixed length. Once declared, they cannot grow | ||
* or shrink in size. */ | ||
let the_array = [1, 2, 3, 4, 5]; | ||
|
||
/* Accessing the array elements */ | ||
let zeroth = the_array[0]; | ||
let first = the_array[1]; | ||
println!("Array elements are {} {}", zeroth, first); | ||
|
||
/* Accessing an array element outside of the bounds result in a 'panic', | ||
* which is a runtime error (and not compile time) */ | ||
|
||
/* Below code creates a panic like this: | ||
* thread 'main' panicked at 'index out of bounds: the len is 5 but the | ||
* index is 10', src/main.rs:71:46 note: Run with `RUST_BACKTRACE=1` | ||
* for a backtrace.*/ | ||
//let index = 10; | ||
//println!("Array element at index is {}", the_array[index]); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#https://stackoverflow.com/q/43667176 | ||
|
||
# Generated files | ||
*/target/* | ||
|
||
# The library shouldn't decide about the exact versions of | ||
# its dependencies, but let the downstream crate decide. | ||
*/Cargo.lock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Exercises | ||
|
||
These are the exercises mentioned at the end of chapter 3 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "fibonacci" | ||
version = "0.1.0" | ||
authors = ["Sohil Ladhani <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] |
Oops, something went wrong.