This code Add a blank at the end of a string str?

what’s the result of this code ? thank you in advance !

i:= str.length-1;
WHILE ( str[i]=' ') DO
        i:=i-1;
END_WHILE
str.length := i+1;

Why not run it and find out?

3 Likes

@ArielLeslie any suggestions for console’s that can run an algorithm like this one ?

you probably need to translate it to a specific language to be able to use it

2 Likes

Thank you for you answer @ilenia , i have a question, if the WHILE DO in that algorithm is the same as do…while in JS ?
and if you know some pure algorithm lessons or courses ? Thank you in advance

the do…while in javascript execute the code at least once, then check if the condition is true to do more iterations

a while loop execute only and until the condition is true

I do not know of any algorithm lessons that are language-agnostic, but any algorithm lesson in a specific language can then by applied to any other language

1 Like

Thank you so much for your time and your answer.