Suppose I have C code below
for(i = 0; i < 10; i++){ printf("Hello"); if(i == 5){ a[3] = a[2] * 2; if(a[3] == b) i = a[3];
How to convert to Ruby? I know that we can skip one iteration with next , but I need to skip several iterations depending on the conditional value, and I don't know how many iterations to skip before starting?
Here is the code I'm actually working on (as Coriward mentioned):
I am looking for a “straight line” in an array where values differ less than 0.1 (less than 0.1 will be considered as a “straight line”). The range must be longer than 50 to be considered a long “line”. After I find the linear range [a, b], I want to skip the iterations to the upper limit of b so that it does not start again with + 1 and it starts looking for a new “straight line” from b + 1
for(i=0; i<arr.Length; i++){ if(arr[i] - arr[i + 50] < 0.1){ m = i; //m is the starting point for(j=i; j<arr.Length; j++){ //this loop makes sure all values differs less than 0.1 if(arr[i] - arr[j] < 0.1){ n = j; }else{ break; } } if(n - m > 50){ //Found a line with range greater than 50, and store the starting point to line array line[i] = m } i = n //Start new search from n }
}
ruby
texasbruce
source share