Take a trip to Okanagan Valley
 

Welcome to our Okanagan Valley Archive. Have fun browsing!

 

(Browse for more articles)

 

In Depth Software Development Strategies, Tip 3: Conditional Statements

The third tip in the series is about clearer the code, the easier it is to
Conditional statementsA neat suggestion find errors later.
was posted as a comment on my last And also dont forget to add comments!
article, suggesting a really good way to
prevent logic errors from creeping into //MyTestClass.java Author: Graham.
your code. Logic errors being the hardest //Desc: Prints out numbers, then the
type of errors to find in computer code even numbers
today.If presented with an if statement: public class MyTestClass
if(num == 0) {
{ ___//Variables
//do something. ___public final int SIZE = 5;
}
___//Main Method, prints numbers o - 4,
Now, if you forgot to put the double then runs doJob() method
equals in the condition like: ___public static void main(String []
if(num = 0) args)
{ ___{
//Do something _____for (int i = 0; i < SIZE; i++)
} _____{
_______System.out.println("number: " +
An error might not be catched, the i);
suggestion put forward was to declare the _____}
constant first, and then the variable ____doJob();
after. ___} //End Main
for example:
if(0 == num) {} , this way if you forget ___public doJob()
one of the equals, the compiler will ___{
catch it.You can take this step further, _____for (int i=0; i < SIZE ; i++
by declaring the 0 as a constant: _____{
public final int ZERO = 0; _______if (i%2 == 0)
if(ZERO == num); _______System.out.println("number: " i);
This just gives your code that extra _____}
step to insure good coding ___}//End doJob
practices.Thank you Jeff, for that great } //END Class
tip!Lets continue,
Since white space is never compiled into Now, if I was going to critique my own
your program, you should never worry code here, I would say that the method
about making your code extra readible doJob() is pretty ambiguous, I should
with space. A lot of the code that I have have called it countEvenNumbers().
tested, has been really hard to traverse
through because the authors havn't left Hope you have found this article useful!
white space between actions, let me Thanks you.Graham McCarthy, has 6 years
demonstrate: experiance developing software for both
educational and business oriented
public class MyTestClass{ purposes.
public final int SIZE = 5; Website:
public static void main(String [] args){
for (int i = 0; i Certification:
public doJob() { - A College Diploma in Computer
for (int i=0; i Programming Analysis from Fanshawe
if (i%2 == 0) College in London, Ontario Canada.
System.out.println("number: " - A University Degree in Information
i);}}}Confused? Frustrated? Good! Technology /w Honours from York
Make your code clear to read; the University in Toronto, Ontario Canada.




www.lodgedinn.com keyword stats [2007-08-19-2007-08-19]



Other search engines trends:



Other search phrases:

london ontario canada canadian travel insurance
canadian travel agencies flights canada to cuba
canada tourist attraction cheap airfare to toronto canada
travel to canada and mexico tourist attractions in quebec canada
manitoba canada tourism canadian pacific hotels
flights to whistler canada hotels in niagara canada
canada theme parks new westminster canada
the docks toronto hotels in canadian rockies
identification needed to travel to okanagan homes for sale
united states documents canada travel passport
hotel in canada city of toronto parks and recreation
population of manitoba lonely planet guide to costa rica
cheap flights from





1- A- B- C- 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-