I want to know how whileTrue: works. I searched the implementation that is in BlockClosure:whileTrue: aBlock     ^ [self value] whileTrue: [aBlock value]And another implementation with no parameter:whileTrue    ^ [self value] whileTrue: []But I don't know how that works, that's a recursive method, but this led me to ask several questions:How does this recursive call terminate?If [self value] returns a Boolean object, why is whileTrue: not implemented in the Boolean type?Why is there another implementation named whileTrue that just do not receive any block and evaluates self?
How does whileTrue: works in Smalltalk?
smalltalk
whileTrue: is inlined by the compiler, that's why you don't see the actual implementation. Here's the comment out of Pharo:Ordinarily compiled in-line, and therefore not overridable.      This is in case the message is sent to other than a literal block.      Evaluate the argument, aBlock, as long as the value of the receiver is true.If you look at the byte code of #whileTrue: you'll see that the compiler simply uses a jump to make the loop:17 <70> self18 <C9> send: value19 <9C> jumpFalse: 2520 <10> pushTemp: 021 <C9> send: value22 <87> pop23 <A3 F8> jumpTo: 17 <---- here's the jump25 <7B> return: nil#whileTrue is also inlined directly (slightly optimized byte code).The inlining is also the reason why there's no implementation of this on Boolean (apart from the fact that there's no point in reevaluating a boolean...).#whileTrue is there so that you can easily create endless loops the only terminate e.g. when the process terminates, a semaphore is signaled, an exception occurs etc. 