You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is one of the most important funtions, the 'main' function, the entry point of many programs. In RUST we use the fn keyword to allow us to declare new functions.
209
-
210
-
For function and variable names, RUST uses snake case, where all letters are lowercase and underscores seperate words. example_snake_case
208
+
There is one of the most important funtions, the 'main' function, the entry point of many programs.
// For function and variable names, RUST uses snake case, where all letters are lowercase and underscores seperate words. example_snake_case
214
+
// Functions are defined by the use of the fn keyword, followed by a function name and a set of parentheses, then a set of curly brackets to tell the compiler where the function body begins and ends.
215
215
216
-
// Functions are declared using the `fn` keyword.
217
-
// The name follows snake_case convention.
218
-
// Function definitions go before they are called.
216
+
fn basic_function() {
217
+
// This function takes no arguments and returns nothing
// Any function can then be called by entering its name followed by a set of parentheses.
226
+
// Functions can be defined before or after your main function, as Rust does not care where you define your functions, you just need to be sure they are defined somewhere in a scope that can be seen by the caller.
// Parameters are variables that are part of a function's signature
245
+
// Functions in Rust can be defined to have parameters. Parameters in functions are special variables that are part of a functions signature. When parameters are defined for a function, you can pass it values for those parameters. Values passed into function parameters are also called arguments. But the words parameter and argument are often used interchangeably in casual conversation to describe the variables in a functions definition or the values passed in when a function is called.
246
+
247
+
// The type of each parameter is required to be declared in function signatures. This is deliberate by design in Rust. To determine what type you are using, The compiler almost never needs you to use them elsewhere, since the type annotations are required in function definitions.
248
+
249
+
// Multiple parameters are defined by separating parameter declarations with commas.
// - Statements: instructions that perform actions and do not return a value
267
271
// - Expressions: evaluate to a value
272
+
// A series of statements optionally ending in an expression are what make up Function bodies. Rust is an expression based language and this is important to understand, as other languages don't have that same distinction.
273
+
274
+
// Statements are instructions that perform some action and do not return a value.
275
+
Expressions evaluate to a resultant value
276
+
277
+
// Function definitions are statements.
268
278
269
-
// For example:
279
+
// Statements do not have return values.
280
+
281
+
// For example, let y = 6 is a statement as it does not have a return value. This in not like other languages where the assignment returns the value of the assignment, such as in C or Ruby.
0 commit comments