Here is what i want.
If word.length() > 0 then delete or insert word.
So, we can structure the code like this:
if(word.length()>0){
if(action.equals("insert")){
insert(word);
}
else if(action.equals("delete")){
delete(word);
}
}
However, the above nested if is hard to read, so we can do
if(word.length()>0 && action.equals("insert")){
insert(word);
}
else if(word.length()>0 && action.equals("delete")){
delete(word);
}
However, the above code repeats word.length() 2 times which lead to duplicates & that is not good. So if we try
if(word.length()>0){
System.out.println("ok to insert or delete");
}
else if(action.equals("insert")){
insert(word);
}
else if(action.equals("delete")){
delete(word);
}
however, the above code will do the Insert or Delete even if word.length==0.
That quite confusing, cos in wiki http://en.wikipedia.org/wiki/Conditional_(programming), they said:
"Only the statements following the first condition that is found to be true will be executed. All other statements will be skipped."
if condition1 then
--statements
elseif condition2 then
-- more statements
elseif condition3 then
-- more statements;
...
else
-- other statements;
end if;
What wiki said mean, if condition1 ==true then do the condition2, but if if condition1 ==false then skip all following conditions (condition2,3,...)
But that does not happen in Java? I am confused??
What wiki said mean, if condition1 ==true then do the condition2What? No.if. There's nothing wrong with it, really.