1. Which keyword is used for conditional execution in Go?
Answer:
Explanation:
The 'if' keyword is used for conditional execution in Go, allowing the program to execute certain code only if a specified condition is true.
2. What is the syntax for a switch statement in Go?
Answer:
Explanation:
In Go, a switch statement is written using the 'switch' keyword followed by the variable being switched on, and the cases inside curly braces.
3. How do you specify a default case in a Go switch statement?
Answer:
Explanation:
The 'default:' case in a Go switch statement is used to specify the code to run if no other case matches.
4. Can the 'if' statement in Go be used without an 'else'?
Answer:
Explanation:
In Go, the 'if' statement can be used without an accompanying 'else' statement.
5. How do you write a loop in Go that repeats a block of code while a condition is true?
Answer:
Explanation:
In Go, the 'for' statement is used for looping, and a 'for' loop with a condition acts like a while loop in other languages.
6. What does a 'break' statement do in a Go loop?
Answer:
Explanation:
The 'break' statement in Go is used to exit a loop immediately, stopping its execution.
7. How do you write an infinite loop in Go?
Answer:
Explanation:
An infinite loop in Go is written using 'for {}', omitting the initialization, condition, and post statements.
8. Is the 'else if' clause available in Go?
Answer:
Explanation:
Go supports 'else if' for multiple conditional branches in an 'if-else' statement.
9. How do you group multiple cases in a single case clause in a switch statement in Go?
Answer:
Explanation:
In Go, multiple expressions can be grouped in a single case in a switch statement by separating them with commas.
10. What is the use of the 'continue' statement in Go?
Answer:
Explanation:
The 'continue' statement in Go skips the remaining code in the current loop iteration and continues with the next iteration.
11. How is the 'fallthrough' keyword used in Go?
Answer:
Explanation:
The 'fallthrough' keyword in Go is used in switch statements to indicate that the execution should continue into the next case clause.
12. Can you nest control structures in Go?
Answer:
Explanation:
In Go, you can nest control structures, such as an 'if' statement inside a 'for' loop, or a 'switch' inside an 'if', etc.
13. What does the 'goto' statement do in Go?
Answer:
Explanation:
The 'goto' statement in Go transfers control to a statement labeled with the corresponding label.
14. How do you execute different cases based on the type of a variable in Go?
Answer:
Explanation:
A type switch in Go allows you to compare the type of a variable and execute different cases based on that type.
15. Can a 'for' loop in Go be used to iterate over elements of a slice or an array?
Answer:
Explanation:
In Go, the 'for' loop can be used with the 'range' keyword to iterate over the elements of a slice or an array.