Home Syntax and semantics Variables and data types If- and switch-statements For- and while-loops Functions Programming product SQL

If- and switch-statements

To do:

Make your own simple program, which demonstrates your knowledge of if- and switch-statements and document your progress on your "studieweb".
For example, make a program, which will give the user different math problems to solve and then tell them, if they are right or wrong.
Remember to explain how both if- and switch-statements work.

My example


If, is a statement you use to give some sort of demand.
For instance in my example I gave the demand to question 1,
that "if" the answer given was 10 then execute the sentence "Exactly!",
but when anything else is answered write "You're dumb! 5+5 is 10".


Switch, is a statement used for changing something.
The switch command creates a dictionary,
and when you then enter some data that matches whith something in its "dictionary"
it responds with the corrosponding answer.
For example in my case when I answer "1" to the question:
Which probem would you like to solve? I get the corrosponding question "What is 5+5".