This repository was archived by the owner on May 23, 2020. It is now read-only.
  
  
  
  
    
    
    
      
    
  
  
    
File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -114,3 +114,47 @@ print 'Good work!!' unless jobNotDone
114114Complex expressions can be created using these operators: E.g. * (x && (y || w)) && z* 
115115Expressions in parentheses are always evaluated before anything outside parentheses.
116116
117+ ## Loops and Iterators  
118+ Use of while:
119+ ``` ruby 
120+ i= 0 
121+ while  i< 5 
122+     puts  i
123+     i= i+ 1 
124+ end 
125+ ``` 
126+ Use of ** until** : continues looping _ until_  the condition given turns to be true. It is compliment to _ while_ .
127+ ``` ruby 
128+ counter =  1 
129+ until  counter ==  11 
130+     puts  counter
131+     counter+= 1 
132+ end 
133+ ``` 
134+ This prints from 1 to 10, each number in new line.
135+ ** _ Note_ ** : These operators are supported in Ruby: += -= * = /=
136+ 
137+ When you don't know how many times you have to loop in, a different syntax of _ for_  can be used. 
138+ ``` ruby 
139+ for  num in  1 ...10 
140+   puts  num
141+ end 
142+ ``` 
143+ This will print numbers from 1 to 9 each in different line.
144+ 1...10 will print 1 to 9
145+ 1..10 will print 1 to 10
146+ 
147+ Ruby supports iterators. One such simple method is ** _ loop_ ** .
148+ ``` ruby 
149+ loop  { print  " Hello there!!" 
150+ ``` 
151+ The curly braces {} are interchangeable with keywords _ do_  and _ end_ .
152+ ``` ruby 
153+ i =  0 
154+ loop  do 
155+   i +=  1 
156+   print  " #{ i } " 
157+   break  if  i >  5 
158+ end 
159+ ``` 
160+ You have to give a condition inside the block which will be used to decide when to break the loop.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments