Tutorial 8 : Cont. Looping
For Loop
For the for loop creation I am not going to take your much time. watch in the picture and i am sure that you will understand it .
Input Output
As you can see there we take an variable of name numbers in which we store 5 variables 1,2,3,4,5 and after that in next line make another variable of name number in the for loop condition it is for taking temporary values of numbers in number and print it in next line we print number. Then we end the loop
Oh! sorry I forgot to tell you about the print statement so let's make difference between puts and print statement
Input Output
The puts give newline command itself but in print statement all will print in the same line.
And in these pictures you will also know that how to print the value of any variables.
Another example of loop
The loops are not only work with numbers they work with records too. For this let's take an example make a record of name groceries and give them values and fill every value of groceries in to food and print it as we can see in pictures
Input Ouput
Range in loops
We can use ranges in the loops also by giving the lower limit and separate it by two dots
Input Output
Here the first # will work as # and the other # will work for print the value of i.
No comments:
Post a Comment