How to resolve the algorithm Loops/While step by step in the Smalltalk programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/While step by step in the Smalltalk programming language
Table of Contents
Problem Statement
Start an integer value at 1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Loops/While step by step in the Smalltalk programming language
Source code in the smalltalk programming language
[s atEnd] whileFalse: [s next. ...].
[foo notNil] whileTrue: [s next. ...].
[...] doWhile: [ ... someBooleanExpression ].
[...] doUntil: [ ... someBooleanExpression ].
[:exit | ... cold ifTrue:[exit value]. ...] loopWithExit
number := 1024.
[ number > 0 ] whileTrue:
[ Transcript print: number; nl.
number := number // 2 ]
number := 1024.
[ number <= 0 ] whileFalse:
[ Transcript print: number; nl.
number := number // 2 ]
You may also check:How to resolve the algorithm Align columns step by step in the Tcl programming language
You may also check:How to resolve the algorithm Peano curve step by step in the Ada programming language
You may also check:How to resolve the algorithm Cuban primes step by step in the REXX programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the Scheme programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the D programming language