Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 and 12.1.2018 - we are on email but incoming phone not available all the time

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
PHP module H104
Control Statements
Exercises, examples and other material relating to training module H104. This topic is presented on public courses Learning to program in PHP, PHP Programming, Beginning PHP - weekend course / hobby / club / leisure users, PHP Programming, Learning to program in PHP

As your program grows, you'll want to repeat sections of your code, or only run some sections in certain circumstances. Loop statements, such as while, and conditional statements, such as if, give you these facilities.

Articles and tips on this subjectupdated
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 ...
3914While, for, foreach or something else to loop.
Newcomers to programming often ask "which loop should I use?" Every language has a while loop, most have a for loop (though sometimes those differ in what they do - Python is an exceptional one, for example), and many have a foreach loop. Then you get the odd ones such as the until loop in Perl ... A ...
3895Flowchart to program - learning to program with Well House
Drawing a flowchart is how many people understand a process; it's something that's been used in schools and textbooks for many generations, and it provides a graphic representation of choices and actions that most people find easy to follow. For newcomers to programming, such as on my Learning to program ...
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 ...
962Breaking a loop - Ruby and other languages
When you're in a loop there are occasions you want to say get me our of this loop NOW, or "I'm done with the current iteration. And those are the 'classic' break and continue statements from C, C++ and Java. Languages like Perl changed break to last and continue to next ... and added a redo that asks ...
2912Predictions for the seagull population
It was the sound of Seagulls outside (what sound do seagulls make? [link]) Well House Manor that go me wondering yesterday "why have we got so many seagulls around here, when we're so far inland". And as I was teaching a "learning to program in PHP" day, I did a bit of research to find out something ...
1199Testing for one of a list of values.
Question [PHP] When you have a string of conditions in an 'if' clause and one side of the conditional expression is the same in each condition, is there any shortcut to avoid writing out every expression in full. For examples, rather than writing if(($name!='Lisa')&&($name!='Leah')&&($name!='Christine')) ...
657The ternary operator in Python
The ? : operator that you may have come across in Perl, PHP, C and Java - known as the ternary or conditional operator - is ABSENT from Python. "But it's so useful" I hear you cry. Ah yes, but isn't this elegant: val = float(raw_input("Age: ")) status = ("working","retired")[val>65] print "You should ...
2304Extracting real data from an exported file in PHP or Perl
"Just give me the data". Where there's a requirement to take data from another program into a Perl or PHP script, it's often easier simply to take the data in a format that it's offered / exported from that other program and use code in Perl or PHP to make appropriate use of that data. The alternative ...
1825Question Mark - Colon operator (Perl and PHP)
The ? and : operator in Perl and PHP allows you to write a single statement that's both an if and an else without the need for all the clutter of keywords, extra variables, and so on if all you want to do is come up with two alternative words. Here's an example in PHP - throwing a number on a die, and ...
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. ! ...
1477Decisions - small ones, or big ones?
When you're traveling, you'll sometimes come to a point at which you make a decision - to go one way or to go another. Sometimes the decision is a small one - for example, if I'm driving through Marlborough there's a choice of the town centre or the road around the back; whichever I take, they come ...
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) ...
1191Smart English Output - via PHP and Perl ? : operator
It's smart to have your program say "there IS in stock" or "there ARE 2 in stock" ... but if you write your code using an "if" and "else" type structure it can become quite verbose. The ? ... : operator - available in many languages including C, Perl and PHP - allows you to write a single "if,else" ...
863Double and Triple equals operator in PHP
Have you been given a piece of code to maintain that has single, double and treble equal operators in it? What's the difference? A single = sign is an assignment - take what's on the right as an expression and save it in the variable named on the left. A double = sign is a comparison and tests whether ...
421Don't repeat code - use loops or functions
I've just answered a question about completing a whole series of radio boxes in a form, where the questioner provided sample code that had the same line, slightly modified, appearing time and time again. But if you find yourself repeating something, there must be an easier way and that way will be either ...
Examples from our training material
bristolgulls.php   Table of calculations
coin.php   switch, case, default and break
condits.php   example simple if statements
floop.php   while, for and foreach loops
houred.php   different image to reflect time of day
if2.php   if, block, else and elseif
ifvswit.php   if v switch / first "step through" application
macorder.php   2 page simple ordering system
timothy.php   demonstration of if / else / while
tt2.php   for loop
tt3.php   lazy operators, increments, +=, ? : and endfor
ttab.php   Temperature table - a while loop
units.php   Conversion of units of area

The ++ operator in PHP - pre-increment and post-increment
While and for, last, next and redo
while and do ... while loops - PHP
increment and decrement operators - PHP
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
Conditional statements - if.
Boolean operators.
blocks, elseif and else.
Conditional statement - switch.
Loops - the while statement.
Making up a table in your PHP.
Alternative loop - the for statement.
Other control statement subjects.
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 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., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/H104.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat