Home Syntax and semantics Variables and data types If- and switch-statements For- and while-loops Functions Programming product SQL

For- and while-loops

To do:

Make a small program, which utilises for- or while-loops in a meaningful way.
Remember to document your progress and explain the code on your "studieweb".
For example, you could make a program, which tries to guess a simple password.
Perhaps one of your own passwords?

Example with "while loop"

While loop

The "while loop" is a command that tells the computer to do a certain task
as long as the conditions which has been given is met.
So it is basicly a block of code and a condition.
So when the program runs, it evaluates if the condition is true
and if it is, the block of code will be executed.
This whole process will keep repeating until the condition becomes false.




Example with "for loop"

For loop

The "for loop" is command used to iterate the sequence of some elements.
You would normally use this sort of command to reapet something x number of times.