[英]Java for loop tricky iteration
I've run the code multiple times wondering what's wrong. 我多次运行代码,想知道什么是错的。
this simple for loop should run 4 times. 这个简单的for循环应该运行4次。 why is it running only twice?? 为什么它只运行两次? Did i miss anything. 我错过了什么。 I'm using android-studio stock emulator api-28 for debugging. 我正在使用android-studio股票模拟器api-28进行调试。
boolean[] booleans = {false, false, false, false};
for(boolean b : booleans){
System.out.println(b);
}
please check the edited code and log cat output. 请检查编辑的代码和日志猫输出。
At first glance, in Android Studio it prints twice or 3 times when debugging, in the Debug tab, but 乍一看,在Android Studio中,它在调试时打印两次或三次, 但在调试选项卡中
the truth is this: 事实是这样的:
I/System.out: Start
I/System.out: false
I/System.out: false
I/chatty: uid=10075(u0_a75) com.xxxxxxxxx.xxxx identical 1 line
I/System.out: false
I/System.out: End
or 要么
I/System.out: Start
I/System.out: false
I/chatty: uid=10075(u0_a75) com.xxxxxxxxx.xxxx identical 2 lines
I/System.out: false
I/System.out: End
as you can see AS instead of printing 因为你可以看到AS而不是打印
I/System.out: false
prefers to print 喜欢打印
I/chatty: uid=10075(u0_a75) com.xxxxxxxxx.xxxx identical 2 lines
Why? 为什么? I can't say. 我不能说。
Maybe something similar happens in the Logcat tab. 可能在Logcat选项卡中发生了类似的事情。
Yes it is similar in the Logcat tab: 是的,它在Logcat选项卡中类似:
2018-12-04 14:16:17.756 2209-2209/com.xxxxxxxxx.xxxx I/System.out: false
2018-12-04 14:16:23.902 2209-2209/com.xxxxxxxxx.xxxx I/chatty: uid=10075(u0_a75) com.xxxxxxxxx.xxxx identical 2 lines
2018-12-04 14:16:24.929 2209-2209/com.xxxxxxxxx.xxxx I/System.out: false
2018-12-04 14:16:25.860 2209-2209/com.xxxxxxxxx.xxxx I/System.out: End
So finally : remove filtering of your output window by deleting "System" and you will see output either like 最后 :通过删除“系统”删除输出窗口的过滤,您将看到输出
I/System.out: false
or 要么
identical 2 lines
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.