Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I skip an iteration if an IF condition becomes true, and go to the first line of do .. end?

I wrote the following code:

require 'net/http'
require 'uri'
require 'IPAddr'
require 'timeout'
require 'Resolv'
require 'open-uri'

#puts "Origin IP:\n\n"
#originip = gets()
(IPAddr.new("209.85.175.120")..IPAddr.new("209.85.175.150")).each do |address|
  uri = URI("http://#{address.to_s}")
  puts "#{uri}"
  http = Net::HTTP.new(uri.host, uri.port)
  puts "#{http}"
  Net::HTTP.start(uri.host, uri.port) do |http|
    request = Net::HTTP::Get.new uri.request_uri
    response = http.request request
    if response.code == "301" || response.code == "400" then

    end
    #request.initialize_http_header({"Origin" => "#{originip}"})
  end

Is it possible to go to line uri = URI("http://#{address.to_s}") in my if condition

if response.code == "301" || response.code == "400" then
 # condition
end

in the above code becomes true? How can I go to the next IP address and skip the current one if my condition becomes true?

Is it possible to do something like a label and goto statement in Ruby?

like image 926
Akash Panchal Avatar asked Nov 28 '22 18:11

Akash Panchal


1 Answers

next if response.code == "301" || response.code == "400"
like image 138
Yoann Le Touche Avatar answered Dec 18 '22 18:12

Yoann Le Touche