How to solve these coding exercises:


Coding Exercise #1

Using a for loop and an if statement print out all the numbers between 1 and 50 that divisible by 7.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #2

Change the code from the previous exercise and use the continue statement to print out all the numbers divisible by 7 between 1 and 50.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #3

Change the code from the previous exercise and use the break statement to print out only the first 3 numbers divisible by 7 between 1 and 50.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #4

Using a for loop, an if statement and the logical and operator print out all the numbers between 1 and 500 that divisible both by 7 and 5.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #5

Using a for loop print out all the years from your birthday to the current year.

Use a variant of for loop where the post statement is moved inside the for block of code.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #6

Consider the following Go program: https://play.golang.org/p/Wo5fIlurnX6

package main
import "fmt"

func main() {
	age := -9
	if age < 0 || age > 100 {
		fmt.Println("Invalid Age")
	} else if age < 18 {
		fmt.Println("You are minor!")
	} else if age == 18 {
		fmt.Println("Congratulations! You've just become major!")
	} else {
		fmt.Println("You are major!")
	}
}

Change the code and use a switch statement instead of an if statement.

Are you stuck? Do you want to see the solution for this exercise? Click here.