Initial commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
## Which one is the correct description for a statement?
|
||||
1. A statement instructs Go to do something *CORRECT*
|
||||
2. A statement produces a value
|
||||
3. A statement can't change the execution flow
|
||||
|
||||
> 2. A statement can't produce a value. However, it can indirectly help producing a value.
|
||||
> 3. It surely can.
|
||||
|
||||
|
||||
## What's the direction of execution in a Go code?
|
||||
1. From left to right
|
||||
2. From top to bottom *CORRECT*
|
||||
3. From right to left
|
||||
4. From bottom to top
|
||||
|
||||
> 2. That's right. Go executes the code from top-to-bottom, one statement at a time.
|
||||
|
||||
|
||||
## Which one is the correct description for an expression?
|
||||
1. An expression instructs Go to do something
|
||||
2. An expression produces a value *CORRECT*
|
||||
3. An expression can change the execution flow
|
||||
|
||||
> 1. It can't. Only a statement can do that.
|
||||
> 3. It can't. Only a statement can do that.
|
||||
|
||||
|
||||
## Which one is the correct description for an operator?
|
||||
1. An operator instructs Go to do something
|
||||
2. An operator can change the execution flow
|
||||
3. An operator can combine expressions *CORRECT*
|
||||
|
||||
> 1. It can't. Only a statement can do that.
|
||||
> 2. It can't. Only a statement can do that.
|
||||
|
||||
|
||||
## Why the following code doesn't work?
|
||||
```go
|
||||
package main
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
"Hello"
|
||||
}
|
||||
```
|
||||
|
||||
1. "Hello" is an expression and it can't be on its own on a single line of code without a statement. *CORRECT*
|
||||
2. By removing the double-quotes surrounding the "Hello". Like this: Hello
|
||||
3. By moving "Hello" out of the func main.
|
||||
|
||||
|
||||
## Does the following code works? And why?
|
||||
```go
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(runtime.NumCPU()); fmt.Println("cpus"); fmt.Println("the machine")
|
||||
}
|
||||
```
|
||||
|
||||
1. It works: Expressions can be typed by separating them using semicolons
|
||||
2. It doesn't work: Statements should be on their own on a single line of code
|
||||
3. It works: Go adds semicolons behind the scenes for every statement already *CORRECT*
|
||||
|
||||
> 1. It works but that's not the reason. And, expressions can't be typed like that.
|
||||
> 2. Are you sure?
|
||||
> 3. That's right. Whether there's a semicolon or not; Go adds them automatically. Those statements are still assumed as they're on a different code line of their own.
|
||||
|
||||
|
||||
## Why this code works?
|
||||
```go
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(runtime.NumCPU() + 10)
|
||||
}
|
||||
```
|
||||
|
||||
1. Operators can combine expressions *CORRECT*
|
||||
2. Statements can be used with operators
|
||||
3. Expressions can return multiple values
|
||||
|
||||
> 1. That's right. + operator combines `runtime.NumCPU()` and `10` expressions.
|
||||
> 2. No, they can't be. For example, you can't do this: `import "fmt" + 3`. Some statement can allow expressions. However, this doesn't mean that they can be combined using expressions.
|
||||
> 3. That's right however it's irrelevant to why this code works.
|
||||
@@ -0,0 +1 @@
|
||||
## Please check out the questions inside the statements directory.
|
||||
68
04-statements-expressions-comments/questions/03-comments.md
Normal file
68
04-statements-expressions-comments/questions/03-comments.md
Normal file
@@ -0,0 +1,68 @@
|
||||
## Why do you need to use comments sometimes?
|
||||
1. To combine different expressions together
|
||||
2. To provide explanations or generating automatic documentation for your code *CORRECT*
|
||||
3. To make the code look nice and beautiful
|
||||
|
||||
|
||||
## Which of the following code is correct?
|
||||
1.
|
||||
```go
|
||||
package main
|
||||
|
||||
/ main function is an entry point /
|
||||
func main() {
|
||||
fmt.Println("Hi")
|
||||
}
|
||||
```
|
||||
|
||||
2. *CORRECT*
|
||||
```go
|
||||
package main
|
||||
|
||||
// main function is an entry point /*
|
||||
func main() {
|
||||
fmt.Println(/* this will print Hi! */ "Hi")
|
||||
}
|
||||
```
|
||||
|
||||
3.
|
||||
```go
|
||||
package main
|
||||
|
||||
/*
|
||||
main function is an entry point
|
||||
|
||||
It allows Go to find where to start executing an executable program.
|
||||
*/
|
||||
func main() {
|
||||
fmt.Println(// "this will print Hi!")
|
||||
}
|
||||
```
|
||||
|
||||
> 1. `/` is not a comment. It should be `//`.
|
||||
> 2. Multiline comments can be put almost anywhere. However, when a comment starts with `/*`, it also needs to end with `*/`. Here, Go doesn't interpret `/* ... */`, it just skips it. And, when Go sees `//` as the first two characters in a code, it skips the whole line.
|
||||
> 3. `//` prevents Go to interpret the rest of the code line. That's why this code doesn't work. Go can't interpret this part because of the comment: `"this will print Hi!")`
|
||||
|
||||
## How should you name your code so that Go can generate documentation from your code automatically?
|
||||
1. By commenting the each line of the code; then it will generate the documentation from whatever it sees
|
||||
2. By starting the comments using the name of the declared names *CORRECT*
|
||||
3. By using multi-line comments
|
||||
|
||||
> 1. This won't help. Sorry.
|
||||
> 3. It doesn't matter whether you type your comments using single-line comments or multi-line comments.
|
||||
|
||||
|
||||
## Which tool do you need to use from the command-line to print the documentation?
|
||||
1. go build
|
||||
2. go run
|
||||
3. go doctor
|
||||
4. go doc
|
||||
|
||||
|
||||
## What's the difference between `godoc` and `go doc`?
|
||||
1. `go doc` is the real tool behind `godoc`
|
||||
2. `godoc` is the real tool behind `go doc` *CORRECT*
|
||||
3. `go` tool is the real tool behind `go doc`
|
||||
4. `go` tool is the real tool behind `godoc`
|
||||
|
||||
> 2. That's right. go doc tool uses godoc tool behind the scenes. go doc is just a simplified version of the godoc tool.
|
||||
Reference in New Issue
Block a user