Categories
Certification Java Programming SCJP

Continue and break, with and without labels, for the SCJP

Looping constructs are very useful in any programming language, however they can be come¬†particularly¬†complex when you have a variety of nested loops and you need to drop out from particular iterations, or exit the loops entirely under a set of given circumstances. Fortunately for us, Java provides us with 2 keywords that we can use […]

Categories
Certification Java Programming SCJP

Looping in Java, a brief look at the various loops and how they can be applied

One of the great features of any programming language is the ability to repeat blocks of code, sometimes indefinately, sometimes until a certain condition is met, or for a set number of iterations. Luckily, Java comes with several flavours of loops, let have a brief look at our options The “for” loop – The for […]

Categories
Certification Java SCJP

Java; the for-each loop, perfect for fondling collections and arrays

The for loop is great, but is it really that nice when you want to iterate over an array or collection? You’d have to do something like the following : Works fine doesn’t it? Looks a bit messy doesn’t it? No need for the index since we only ever use it to get the current […]

Categories
Certification Java SCJP

The do-while loop, always executes at least once…

As I’ve covered in a previous post regarding the while loop, the do-while, often refered to as the do loop is very similar. Lets have a look at the psuedo code. So as we can see, the actual body of the loop gets executed at least once before the boolean expression is ever evaluated. Now […]

Categories
Certification Java SCJP

Using while loops, for when you don’t know how long the piece of string is…

Just another bitesize SCJP post here, looking at the while loop in Java. There may be times, where you need to continually iterate over a code block for an unknown number of times. What you can do, is to loop through a code block while a condition is true, something else might change that condition, […]

Categories
Certification Java SCJP

Playing with the For loop in Java…

The for loop is an extremely flexible and powerful way of iterating over a code block for a set number of times. Generally speaking, this type of loop is great for situations when you need to repeat code for a definitive number of times, for example you know that your shopping basket contains 10 items, […]