Java For Beginners Guide To Learn Java And Java Programming (Java Programming Books) by Josh Thompsons

Java For Beginners Guide To Learn Java And Java Programming (Java Programming Books) by Josh Thompsons

Author:Josh Thompsons [Thompsons, Josh]
Language: eng
Format: epub
Published: 2017-03-15T07:00:00+00:00


Chapter Summary:

In this chapter, we have covered the following concepts:

The IF statement structure and use

How to use Conditional Operators

How to construct and use the IF … ELSE statement

How to construct and use the IF … ELSE IF statement

How to construct and use Nested IF statements

What Boolean values are and how to use them

How to construct and use a switch statement

Chapter 3: Statements – Looping and Iteration

As I said to you earlier, your programming is sequential, meaning it flows from the top down, each line of code executed unless Java is told otherwise. In the last chapter, we looked at how to use the IF statement to tell Java that you don’t want every line executed. But there is another way of interrupting the flow and that is to use loops. Loops force a program to go back to the beginning, or to a specified place, allowing you to execute code repeatedly. Let’s look at an example; let’s say that you wanted to add the numbers from 10 through to 20. It is quite easy to do that in Java:

As an example, suppose you wanted to add up the numbers 1 to 10. You could do it quite easily in Java like this:

int addition = 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20;

That method is fine for just a few numbers but what if you wanted to add all the numbers from 1 to 500 or 1000? We would use a loop on a line of code repeatedly until we got to 500 or 1000 then we would exit the loop and carry on.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.