Re: For loops trouble
Daniel Johnson wrote in post #993238:
I am trying to translate a program I have in Java into ruby and having
trouble translating this for loop
for(int i = 0; a[i] < x;i++)
I tried this
for i in a[i]...x
but it produce some errors. Any help will be appreciated. Thank you.
Ruby has a for-in loop:
a = [2, 4, 1, 9, 6]
x = 7
for num in a
break if num > x
puts num
end
But a for-in loop calls each(), so ruby programmers just use each()
directly:
a.each do |num|
break if num > x
puts num
end
--
Posted via
http://www.ruby-forum.com/.
.
Relevant Pages
- Re: count occurences of font color
... Dim num As Long, res As Long ... Debug.Print Timer - s ... ' using isnull and not using characters ... as the loop will exit on the first character. ... (microsoft.public.excel.programming) - Interesting behaviour with lexical variable
... use warnings; ... I found out that once the loop get executed for the second ... sub main { ... Variable "$num" will not stay shared at x.pl line 11. ... (comp.lang.perl.misc) - Re: count occurences of font color
... Dim num As Long, res As Long ... Debug.Print Timer - s ... ' using isnull and not using characters ... as the loop will exit on the first character. ... (microsoft.public.excel.programming) - Re: WHILE LOOP NOT WORKING IN INCLUDE ASP FILE - LOOPING FOREVER
... I have an issue with the while loop in include file. ... I see that the ONLY field you are using is the NUM ... Change the query ... provided by the recordset, Bottom line: you do not need a cursor. ... (microsoft.public.data.ado) - Re: threads question
... loop) before process 2 ever gets started. ... i is already equal to 5 so the while loop never executes and num ... time slice is up and process 1 runs again. ... Mr. Bazarov points out, C++ has no help for you. ... (comp.lang.cpp) |
|