I want to create logic such that: if s2 is null the debugger skips all the complex string manipulation and returns null instead of s1 + s2 + s3 as seen in the first if block. Am I wrong somewhere?
public static String helloWorld(String s1, String s2, String s3){
if(s2==null){
continue;
return null;
}
... lots of string manipulation involving s1, s2 and s3.
return (s1+s2+s3);
}
don't use continue there, continue is for loops, like
for(Foo foo : foolist){
if (foo==null){
continue;// with this the "for loop" will skip, and get the next element in the
// list, in other words, it will execute the next loop,
//ignoring the rest of the current loop
}
foo.dosomething();
foo.dosomethingElse();
}
just do:
public static String helloWorld(String s1, String s2, String s3){
if(s2==null){
return null;
}
... lots of string manipulation involving s1, s2 and s3.
return (s1+s2+s3);
}
The continue statement is used for loops (for, while, do-while), not for if statements.
Your code should be
public static String helloWorld(String s1, String s2, String s3){
if(s2==null){
return null;
}
... lots of string manipulation involving s1, s2 and s3.
return (s1+s2+s3);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With