Ruby: why do while and until not return last line they execute from a function? -


I hope the loop of a time comes back to execute the last statement, but does not return a function Does

(1) It starts working ..

  [10] pry (main)> Counter = 0 = & gt; 0 [11] PRI (Main) & gt; A = counter + = 1 while the counter & lt; 10 = & gt; Nil [12] PRI (Main) & gt; A = & gt; 10   

(2) This does not work as much as I expected. I hope 10 will be returned and stored in b .

  [19] Pry (main)> gt; Def increase (Terminal_value) [19] PRI (Main) * Counter = 0 [19] PRI (Main) * While counter & lt; Terminal_Value [19] PRI (Main) * Counter + = 1 [19] PRI (Main) * End [19] PRE (Main) * end = & gt; : Increase in salary [20] PRI (Main)> B = increment (10) = & gt; Nil [21] PRI (Main) & gt; B = & gt; Zero   

Question:

  • Why, in (1) , does Zero return from the assignment statement?
  • Why was not b assigned to 10 ?

    Update:

    Outlined as @DaveNewton, in (1) , I thought I Was doing:

      one = (counter + = 1 counter while <10)   

    but I was actually doing:

      (a = counter + = 1) counter & lt; 10    

    Both in their instances, while Zero .

    while is a result of zero as long as break is used to provide value Is done for

    For the same:

    As a while loop zero until Break is used, by the result loop.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -