Tutorial 7 : Looping
Loop do
As you all know that looping is the most important part of programming. For the loop creation we is to simply write loop and followed by do. After that we is to create increment or decrements conditions for the loop. For ex. x += 1 (is a short cut of x = x + 1) after that we is to use the loop and then the breaking condition for the end of the loop. One thing most important in this is never forget to end your loop if loop is there end it otherwise it will continuously work on your whole program. So let's check it out .
Input Output
In this program we take an variable x and give it value 1. Then we start our loop by writing "loop do" and then increment by 1. After that we create condition for every value of x is even. Then we printing value of x. After that break statement for stop the loop and in next line end is for ending the loop and the output will be 2 4 6 8 10.
Loop While
For the while loop creation we is to simply write while. After that we is to create increment or decrements conditions for the loop. For ex. y += 1 (or we can write y++) no breaking condition is use for the ending of the loop. Just end it with end keyword and get the profit of the loop. So let's check it out .
Input Output
In this program we take an variable y and give it value 1. Then we start our loop by writing "while" and in this loop we give condition with the while keyword then increment by 1. After that we create condition for every value of y is even. Then we printing value of y. After that we print the value of y and in next line end is for ending the loop and the output will be 2 4 6 8 10.
Until Loop
For the until loop creation we is to simply write until. After that we is to create looping condition and increment or decrements conditions for the loop. For ex. a += 1 (or we can write a = +1 ) no breaking condition is use for the ending of the loop. Just end it with end keyword and get the profit of the loop. So let's check it out .
Input Output
In this program we take an variable a and give it value 1. Then we start our loop by writing "until" and in this loop we give condition with the while keyword then increment by 1. After that we create condition for every value of a is even. Then we printing value of y. After that we print the value of a and in next line end is for ending the loop and the output will be 2 4 6 8 10.
No comments:
Post a Comment