loop with a break. counter = 5 factorial = 1 while True: factorial *= counter counter -= 1 if counter == 0: break print(factorial) Racket In Racket, as in other Scheme implementations, a "named-let" is a popular way to implement loops: #lang racket (define counter 5) (define factorial 1) (let loop () (set! factorial (* factorial counter)) (set! counter (sub1 counter)) (when (> counter 0) (loop))) (displayln factorial) Compare this with the first example of the while loop example for Racket. Be aware that a named let can also take arguments. Racket and Scheme also provide a proper do loop. (define (factorial n) (do ((counter n (- counter 1)) (result 1 (* result counter))) ((= counter 0) result) ; Stop condition and return value. ; The body of the do-loop is empty. )) Ruby counter = 10 factorial = 2 begin factorial *= counter counter -= 2 end while counter > 1 puts factorial Smalltalk | counter factorial | counter := 5. factorial := 1. [counter > 0] whileTrue: [factorial := factorial * counter. counter := counter - 1]. Transcript show: factorial printString Swift Swift 2.x and later: var counter = 5 var factorial = 1 repeat { factorial *= counter counter -= 1 } while counter > 0 print(factorial) Swift 1.x: var counter = 5 var factorial = 1 do { factorial *= counter counter -= 1 } while counter > 0 println(factorial) Visual Basic .NET Dim counter As Integer = 5 Dim factorial As Integer = 1 Do factorial *= counter counter -= 1 Loop While counter > 0 Console.WriteLine(factorial) See also Control flow For loop Foreach Repeat loop (disambiguation) While loop References External links do {...} while (0) in C macros Control flow Articles with example Ada code Articles with example C code Articles with example Fortran code Articles with example Pascal code Articles with example Racket code Articles with example Python (programming language) code de:Schleife (Programmierung)#Do-While-Schleife