Functions and iterations in Silq
Functions are blocks of reusable code that are organized in a way such that it brings modularity to your code and makes your code clear and legible to read. Just as with any other programming language, Silq offers some built-in functions to use and lets us define our custom functions according to our requirements. For example, you have already seen H()
in the preceding code blocks, which is a Hadamard function and a built-in function.
Iterations in computer programming are the repeated execution of code statements until they meet a certain condition. These are also known as loops in computer programming. Silq offers two different kinds of iteration statements, namely while
and for
loops.
Let's now see some example code where iterations are being implemented inside a function. Please note that to run Silq programs, it is important that you always define a function called main()
and then execute your code inside that function. You can create...