Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Chisisi Massri   on May 08 In Java Category.

  
Question Answered By: Gorkem Yilmaz   on May 08

Because you have a carrage return after the if(j%2==0) instead of the
following line.

these are good examples of if statements:

if (something) doStuff();

if (something){
doStuff();
} else {
doOtherStuff();
}

These are dangerous examples:

if (something)
doStuff;

if (something) doStuff;
else doOtherStuff();

Now why are the second lot more dangerous the the first lot?

Well basicly they have less chance to be magicaly broken during the
coding process. If we changed ...

if (something)
doStuff;

to

if (something)

doStuff();

it won't work because of the extra carrage return.

Errors like that are realy hard to find in large code ... or even small
code when youa re first starting.

As messy as it looks at first I would always recommend new coders to
always put blocks around a if statement  ... even if it is only one thing
they are putting in the if statement.
i.e.
if (something) {
doStuff();
}

This leads to good coding practices and it leads to less mistakes.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on why it doesn't go into the if statement? Or get search suggestion and latest updates.


Tagged: