while loop in Julia
In Julia, while loop is used to execute a block of statements repeatedly until a given condition is satisfied. And when the condition becomes false, the line immediately after the loop in the program is executed. If the condition is false when the while loop is executed first time, then the body of the loop will never be executed.

Syntax :
while expression
statement(s)
end
Here, ‘while‘ is the keyword to start while loop, ‘expression‘ is the condition to be satisfied, and ‘end‘ is the keyword to end the while loop.
Note: A block of code is the set of statements enclosed between the conditional statement and the ‘end‘ statement.
Example 1:
# Julia program to illustrate # the use of while loop # Declaring ArrayArray = ["Geeks", "For", "Geeks"] # Iterator Variablei = 1 # while loopwhile i <= length(Array) # Assigning value to object Object = Array[i] # Printing object println("$Object") # Updating iterator globally global i += 1 # Ending Loopend |
Output:
Example 2:
# Julia program to generate # the Fibonacci sequence # The length of Fibonacci sequencelength = 15 # The first two valuesa = 0b = 1 # Iterator Valueitr = 0 # while loop conditionwhile itr < length # Printing fibonacci value print(a, ", ") # Updating value c = a + b # Modify values global a = b global b = c # Updating iterator global itr += 1 # End of while loopend |



