Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Java module J704
Loops and Conditional Statements
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 listing
Solution Centre - all article listing

Articles and tips on this subjectupdated
4427Java example - for loop and conditionals from course exercise
Most of our training modules have exercises at the end (sometimes in the middle too) to help delegates checkpoint their understanding, and to give the tutor feedback as to how they're doing, and what coding techniques and habits they're bringing from other languages. With the exercises, there's rarely ...
4346A behaviour driven example of writing a Java program
A new exercise example just posted from the Java course I'm running this week - contionals, loops, and a few static functions. The question is to rea from the user how many tables there are in a restaurant, then read the width and length of each table and report on the number of people who can be seated ...
4323Learning to program - Loop statements such as while
If your program always ran each statement just once (indeed skipping over statements which were in blocks in false conditions) it would run very quickly and would have little use. You couldn't (for example) run a program which went through a whole series of results from a database query and displayed ...
4322Learning to Program - the conditional statement (if)
Every language has some sort of conditional statement. That's a way of looking at some sort of setting or status in the program and performing some sort of action based on that setting or status. such statements take the form ...   if {some sort of condition is true} then {run a group of ...
3200How 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 ...
3397Does 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 ...
3038Setting 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 ...
2734for 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 ...
1696Saying 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. ! ...
1582Ruby, 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 ...
1220for 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) ...
353Wimbledon 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 ...
Examples from our training material
Bills.java   Nested loops, conditionals, breaks, labels etc
Capacity.java   Course Exercise - capacity of tables in a restaurant
Day2a.java   Sample program for exercise
Firstif.java   Example of a first if statement
Forloop.java   the 'for' loop in Java
Loop1.java   'While' loop example
Loop2.java   Breaking from a loop
Newtab.java   First read - calculate - loop program
Secondif.java   Nested 'ifs', and 'else'
Sindoll.java   Excerise - Singapore to US Dollar table
Updown.java   Example of a boolean variable
Studying Java!
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
"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,Ruby, Lua, 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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/J704.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb