DO WHILE

DO WHILE

The "do-while" loop is another type of control flow statement that is similar to the "while" loop. The key difference is that in a "do-while" loop, the condition is checked after the code block is executed. This means that the code block is guaranteed to be executed at least once, regardless of the condition.

The general syntax of a "do-while" loop is as follows:

SYNTAX:

do: # Code block while condition

Here's an example to demonstrate the usage of a "do-while" loop:

CODE:

count = 0 do: print("Count:", count) count += 1 while count < 5

In this example, the code block inside the loop is executed first, which prints the value of count and increments it by 1. Then, the condition count < 5 is checked. If the condition is true, the loop continues and the code block is executed again. This process repeats until the condition becomes false

OUTPUT:

Count: 0 Count: 1 Count: 2 Count: 3 Count: 4





Comments

Popular posts from this blog

Fibonacci Series

COMPARISION EXPRESSION

LOGICAL EXPRESSION