Exercises, examples and other material relating to training module J704. This topic is presented on public courses
Learning to Program in Java,
Java Bootcamp,
Java Programming for the Web
Unless otherwise specified, code runs from top to bottom, very much in the manner that you read a book. Conditional statements such as "if" allow the programmer to choose whether or not blocks of the code are to be skipped over, and loops such as "while" allow blocks of code to be repeated.
Related technical and longer articles
Solution Centre - all article listingSolution Centre - all article listing
| Articles and tips on this subject | updated |
| 3397 | Does a for loop evaluate its end condition once, or on every iteration? All the languages that we teach have a for loop or the equivalent, which is a clean way of repeating a block of code with a rising or falling index number. It's used in many circumstances - for example in iterating through the months of the year (for m goes from 1 to 12) of in stepping through all ... | 2012-04-15 |
| 3200 | How a for loop works Java, Perl and other languages Java, Perl, PHP, Ruby, C, C++, Tcl and many other languages support a "for" loop construct.
When your program enters the top of the loop, it performs the first statement in the brackets ... in this Perl example, that's to initialise the $now variable to 1. It then evaluates the expression given as ... | 2011-03-18 |
| 3038 | Setting up individual variables, and arrays, in Java - some commented examples In Java, variables must be defined before they have an initial value assigned to them, and they must have an initial value assigned to them before the value thay contain is used; there's no automatic assumption that a new name is a variable, nor is there an assumption made of what type of data a variable ... | 2010-11-09 |
| 2734 | for and foreach in Java Java has had a "traditional" for loop from the beginning:
for (int k=0; k<Allwords.size(); k++) {
That's three semicolon separated elements:
• initial setting
• test to see if loop should continue
• action to be taken before each re-test
So that when that's used in a loop ... | 2010-04-23 |
| 1696 | Saying NOT in Perl, PHP, Python, Lua ... "Isn't there one standard way to say NOT?" asked one of my delegates on today's course - and it's an excellent question. But the answer to a question about a negative subject is itself in the negative - no, there isn't just a single way!
In fact .. I can think of no fewer that 12 ways!
• 1. ! ... | 2008-07-05 |
| 1582 | Ruby, C, Java and more - getting out of loops break and continue statements have been available for loop control for many years, and others functionallity has been added such as Perl's redo. From today's Ruby Course, here's a table that compares these loop controls in Ruby to similar commands in the other languages that I have been discussing ... | 2008-03-19 |
| 1220 | for loop - how it works (Perl, PHP, Java, C, etc) When writing a program, you'll often want to repeat a block of code, counting up through a table or performing a block of code with an input value (loop counter) that goes up 1, 2, 3, 4 etc.
You COULD do this using a while loop, but this means you have to specify each of
• how to start (initialise) ... | 2007-06-07 |
| 353 | Wimbledon Neck What use is the "+=" operator? Why did the language designers bother to provide it? Yet they did ...
In Perl and PHP
$number_on_bus = $number_on_bus + $goton_here;
becomes
$number_on_bus += $goton_here;
In Python
number_on_bus = number_on_bus + goton_here
becomes
number_on_bus += goton_here
In ... | 2006-06-05 |
2275
Examples from our training material
Pictures
Studying Java!
Background information
This module is available under an
Open Training Notes License for free download from
http://www.training-notes.co.uk.
Topics covered in this module
Booleans.
"if" statement.
"while" loop.
"for" loop.
Labels and breaks.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Java,
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if
you live in a different
country or continent to us.
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.