Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
Decisions - 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 back together again very quickly. And at other times the decision is much bigger - we decided to fly on our recent trip to Slovenia, and once that decision was made and we started to act on it, the whole course of our time from Sunday lunchtime through to the following Friday evening was mapped out as alternative "B" rather than "A".

All the programming languages that we teach have conditional statements - if statements, or commands - and there's a requirement in every language to define the start and end of the conditional code - where the two tracks merge again, as well as where they separate. There are a variety of ways of doing this - using insets (Python), using an endif, if or do, done pair (Shell programming) but perhaps the most common is to use curly braces. That applies in PHP and in C (today's example) and - slightly varied - in Perl and Tcl.

#include <stdio.h>
  
int main() {
  int dayslong;
  printf("How long is the course ");
  scanf("%d",&dayslong);
  
  /* Condition applies only to first printf */
  if (dayslong < 5)
    printf ("Less than a week\n");
    printf ("No weekend activities\n");
  printf ("First Job done\n");
  
  /* Condition applies to TWO printf-s */
  if (dayslong < 5) {
    printf ("Less than a week\n");
    printf ("No weekend activities\n"); }
  printf ("Second Job done\n");
}


In the first section, no curly braces are used and so the condition applies ONLY to the first printf, but in the second section with curly braces, the condition applies to the first and second printfs.

Let's run that ...

How long is the course 7
No weekend activities
First Job done
Second Job done
[trainee@daisy cd07]$ ./cb
How long is the course 4
Less than a week
No weekend activities
First Job done
Less than a week
No weekend activities
Second Job done
[trainee@daisy cd07]$(written 2007-12-18, updated 2007-12-19)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H104 - PHP - Control Statements
  [3914] While, for, foreach or something else to loop. - (2012-11-06)
  [3895] Flowchart to program - learning to program with Well House - (2012-10-14)
  [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
  [3200] How a for loop works Java, Perl and other languages - (2011-03-12)
  [2912] Predictions for the seagull population - (2010-08-09)
  [2304] Extracting real data from an exported file in PHP or Perl - (2009-07-25)
  [1825] Question Mark - Colon operator (Perl and PHP) - (2008-10-08)
  [1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
  [1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
  [1199] Testing for one of a list of values. - (2007-05-22)
  [1191] Smart English Output - via PHP and Perl ? : operator - (2007-05-18)
  [962] Breaking a loop - Ruby and other languages - (2006-12-03)
  [863] Double and Triple equals operator in PHP - (2006-09-12)
  [657] The ternary operator in Python - (2006-03-25)
  [421] Don't repeat code - use loops or functions - (2005-08-21)
  [406] Assignment, equality and identity in PHP - (2005-08-08)
  [353] Wimbledon Neck - (2005-06-20)
  [340] Code and code maintainance efficiency - (2005-06-08)

P204 - Perl - Conditionals and Loops
  [4031] Showing what programming errors look like - web site pitfall - (2013-03-06)
  [3004] Increment operators for counting - Perl, PHP, C and others - (2010-10-18)
  [2832] Are you learning Perl? Some more examples for you! - (2010-06-27)
  [2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast - (2010-04-07)
  [2550] Do not copy and paste code - there are much better ways - (2009-12-26)
  [2351] Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12)
  [1727] Equality and looks like tests - Perl - (2008-07-29)
  [1607] Learning to program in Perl - (2008-04-11)
  [1468] Lexical v Arithemetic testing, Bash and Perl - (2007-12-11)
  [930] -> , >= and => in Perl - (2006-11-18)

T203 - Tcl/Tk - Conditionals and Loops
  [3571] Comparing loop commands in Tcl - (2012-01-06)
  [3570] Trapping errors in Tcl - the safety net that catch provides - (2012-01-06)
  [3189] Tcl - the danger of square brackets in a while command - (2011-03-02)
  [2681] Tcl - a great engineering language - (2010-03-17)
  [2471] A short form of if ... then ... else - (2009-10-23)
  [2261] Tcl - nice and nasty - (2009-06-29)
  [1401] Tcl - using [] or {} for conditions in an if (and while) - (2007-10-23)
  [210] Joining lists in Tcl. Indirect variables in Tcl. - (2005-02-12)

Y103 - Python - Conditionals and Loops
  [4210] If elif elif elif - multiway selection in Python - (2013-11-16)
  [4092] Identity in Python - (2013-05-17)
  [3762] Learning to program - the if statement. Python. - (2012-06-12)
  [3620] Finding the total, average, minimum and maximum in a program - (2012-02-22)
  [3558] Python or Lua - which should I use / learn? - (2011-12-21)
  [3439] Python for loops - applying a temporary second name to the same object - (2011-09-14)
  [3083] Python - fresh examples from recent courses - (2010-12-11)
  [2899] Groupsave tickets - 3 or 4 train tickets for the price of 2 - (2010-08-02)
  [2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
  [1661] Equality, sameness and identity - Python - (2008-05-31)
  [1201] No switch in Python - (2007-05-23)
  [909] Python is like a narrowboat - (2006-10-30)
  [835] Python - when to use the in operator - (2006-08-16)
  [788] New - Conditional expressions in Python 2.5 - (2006-07-01)
  [668] Python - block insets help with documentation - (2006-04-04)
  [299] What - no switch or case statement? - (2005-05-03)


Back to
Shopping for Christmas and looking forward
Previous and next
or
Horse's mouth home
Forward to
Some new C programming examples - files, structs, unions etc
Some other Articles
The Christmas Letter
Next course - 7th January 2008, Regular Expressions
FSB leaves its members feeling like mushrooms
Some new C programming examples - files, structs, unions etc
Decisions - small ones, or big ones?
Shopping for Christmas and looking forward
Tcl/Tk - updating your display while tasks are running
Using Tcl/Tk resource files for flexible applications
Making a variable dynamically visible in a Tcl/Tk GUI
The Horse goes on and on
4285 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

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

PAGE: http://www.wellho.net/mouth/1477_Dec ... ones-.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat