gpt4 book ai didi

java - Java 函数中的 Continue 语句

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:11:40 24 4
gpt4 key购买 nike

我想创建这样的逻辑:如果 s2 为 null,调试器将跳过所有复杂的字符串操作并返回 null 而不是 s1 + s2 + s3,如中所示第一个 if block 。我哪里错了吗?

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);
}

最佳答案

不要在那里使用continue,continue是for循环,比如

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();
}

只是做:

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);
}

关于java - Java 函数中的 Continue 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12481157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com