i have if-statement this:
if (condition1 || condition2) { //do stuff here //small things happened here //more stuff if (condition1) { system.out.println("thank"); // task alpha // task beta } else { system.out.println("you"); // task delta // task gamma } }
so basic idea if statement happens when either of conditions true (in case, both conditions cannot true @ same time).
however, once inside if statement, there point if first condition true, print "thank" , execute task alpha , beta. if second condition true, print "you" , execute task delta , gamma. lot of common statements executed before reach diverging point.
is best/simplest way of writing whole if statement?
thanks.
you use ternary inner if
string toprint = test == null ? "thank" : "you"; system.out.println(toprint);
or
system.out.println(test == null ? "thank" : "you");
Comments
Post a Comment