The output -1 becomes a slash in the loop

This can be reliably reproduced (or not reproduced, depending on what you want) with openjdk version “1.8.0_222” (used in my analysis), OpenJDK 12.0.1 (according to Oleksandr Pyrohov) and OpenJDK 13 (according to Carlos Heuberger). I ran the code with -XX:+PrintCompilation enough times to get both behaviours and here are the differences. Buggy implementation (displays output): … Read more

Purpose of while(1); statement in C

Please note that all valid statements of the language do not have to serve a purpose. They are valid per the grammar of the language. One can build many similar “useless” statements, such as if (1);. I see such statements as the conjunction of a conditional (if, while, etc.) and the empty statement ; (which … Read more

How do you detect when a sound file has finished?

You can use the MediaPlayer class and add a Completion listener to be activated when the sound finishes playing MediaPlayer mp = MediaPlayer.create(this,Uri.parse(“android.resource://emad.app/raw/seven_chimes”)); mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { performOnEnd(); } }); mp.start();

How do I replace while loops with a functional programming alternative without tail call optimization?

An example in JavaScript Here’s an example using JavaScript. Currently, most browsers do not support tail call optimisation and therefore the following snippet will fail const repeat = n => f => x => n === 0 ? x : repeat (n – 1) (f) (f(x)) console.log(repeat(1e3) (x => x + 1) (0)) // 1000 … Read more

While loop in batch

set /a countfiles-=%countfiles% This will set countfiles to 0. I think you want to decrease it by 1, so use this instead: set /a countfiles-=1 I’m not sure if the for loop will work, better try something like this: :loop cscript /nologo c:\deletefile.vbs %BACKUPDIR% set /a countfiles-=1 if %countfiles% GTR 21 goto loop