Reputation: 33
I've run the code multiple times wondering what's wrong.
this simple for loop should run 4 times. why is it running only twice?? Did i miss anything. I'm using android-studio stock emulator api-28 for debugging.
boolean[] booleans = {false, false, false, false};
for(boolean b : booleans){
System.out.println(b);
}
please check the edited code and log cat output.
Upvotes: 3
Views: 330
Reputation: 164089
At first glance, in Android Studio it prints twice or 3 times when debugging, in the Debug tab, but
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
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.
Yes it is similar in the Logcat tab:
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
Upvotes: 5