2

Why in this loop "hello world" is shown just 2 times, not 20 times?

 for(int j=0; j<20; j++){
   Log.d("myTag","hello world");
 }

Please explain what's going on.

kenny_k
  • 3,831
  • 5
  • 30
  • 41

2 Answers2

0

Maybe this is because of identical tag names or messages. Seems that it doesn't allow more than two same logs. You can use

for(int j=0;j<20;j++){
    Log.d("myTag" + j,"hello world");
 }

or

for(int j=0;j<20;j++){
    Log.d("myTag","hello world" + j);
}
Alina
  • 424
  • 1
  • 4
  • 17
0

In logcat you can see these lines, enter image description here

Also you have the same issue with this loop:

for (j in 0..19) {
            Log.d("myTag", "${j/20}")
        }

But this loop runs as desired:

for (j in 0..19) {
            Log.d("myTag", "$j")
        }

Apparently Android Studio doesn't show identical logs. Also see these two links: android logcat logs chatty module line identical message and android logcat logs chatty module line expire message

MMG
  • 3,226
  • 5
  • 16
  • 43