Blogs Article

Coding for Noobs! [Programming Tutorial Series] Tutorial 5: Using Conditions

  • 439 views 0 today
  • 3
  • 1
  • 1
999Destroyer
Lvl 44Master Technomancer
64
Alrighty guys! I'm back with another tutorial. This time we will be taking what we learned last time and apply it to making a more sophisticated program. Before we get into this, I would like to teach you a bit about conditions. This is basicly asking the program if something is true or not. To do this, we are going to write the following under what we did last time in the main method:Image

Now let's break it down bit by bit. We start off like last time, asking the user a question. But this time we will check the user's answer and print out the next line accordingly. What this code is saying, is that if what the user said contains the word "hot" (eg. "I like it when it's hot" or "I like hot" will be accepted), then the user will be told that he has spawned in a desert. But if the user input doesn't contain "hot", we will move on to the next condition, which is checking if the user input contains the word "cold". If this is true, then the user will be told that he/she has spawned in a taiga. Finally, "else" means that if none of the above conditions are met, the following will execute. In this case, if the user doesn't want to answer correctly, we will say that he/she spawned in lava and died.

Let's use name once more and where it says: "You have spawned in lava and died! Game over!", we will make it actually say the user's name by turning into: "You have spawned in lava and died! Game over " + name + "!". As you can see, this concept can be useful in making interactive stories or text RPGs. If you did everything right, your final product should look something like this:

Image

That's all for now guys! Remember, you can make this into a runnable application like you did last time. Check out the previous tutorial if you forgot how. Be sure to give me a diamond and even a favourite if this helped, subscribe for more, and let me know in the comments what you want me to show you next! Check out the next blog here: http://www.planetminecraft.com/blog/coding-for-noobs-programming-tutorial-series-tutorial-6-making-a-window/.

  Have something to say?

jscooly555
01/27/2014 9:51 pm
Level 31 : Artisan Dragonborn
Maybe the next thing should be... HOW SHOULD I KNOW! Your teaching me after all! idk, just something better and better! Keep it going!
1

Welcome