logo
down
shadow

While loop Int return inside the method completely dead


While loop Int return inside the method completely dead

By : daniel kim
Date : November 24 2020, 03:01 PM
I think the issue was by ths following , Based on your description, I changed some of your code and added another system to check continue or exit. This works:
code :
public static boolean CheckcollectInteger(int inputValue,int minimum, int maximum){
            if (inputValue >= minimum && inputValue <= maximum){
                return true;       
            }else {
                return false;
            }
    }

   public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            final int MINIMUM =0, MAXIMUM =100;

            while(true){
                System.out.print("Enter a number of cats :");
                int catsNumber;
                //check input is integer or not
                try{
                    catsNumber = in.nextInt();
                }catche(Exception e){
                   System.out.println("Value needs to be an integer. Try again");
                   continue;
                }
                //check input valie is btw 0-100 or not
                boolean catInputCheck =  CheckcollectInteger(catsNumber,MINIMUM, MAXIMUM);
                if (catInputCheck){
                    System.out.printf("Your number of cats was %d", catsNumber);
                }else {
                    System.out.println("Value needs to be an integer between 0 and 100. Please try again.");
                }

                //----check continue or exit system
                System.out.print("Do you want to continue ? (yes / no)");
                String isContinue = in.nextLine();
                if(isContinue.equals("no") || isContinue.equals("NO")){
                    break; //exit loop
                }
            }
            in.close();     
        }


Share : facebook icon twitter icon
What could cause the dead loop, indicated by print "Dead loop on virtual device " in linux kernel?

What could cause the dead loop, indicated by print "Dead loop on virtual device " in linux kernel?


By : Michael Caudy
Date : March 29 2020, 07:55 AM
I hope this helps you . Ok, Got it.
This typically happens when you enter the same function twice, referencing to the same kernel resource, in a single execution context of the linux kernel (e.g. a single instance of softIRQ, etc). The way out of this is to make sure you don't re-enter the function twice in the same execution context. It's a bug in your code if this happens.
Can't get a return value from a foreach loop inside a method

Can't get a return value from a foreach loop inside a method


By : aj91
Date : March 29 2020, 07:55 AM
This might help you Whichever recursive invocation finds your node will return it, but unless it's the top-level that value just gets ignored. You probably meant to do something like:
code :
    else
    {
        string value = get_nodes_value(arg_node.ChildNodes, node_name);
        if (value != "")
            return value;
    }
using return inside loop and method

using return inside loop and method


By : Wix
Date : March 29 2020, 07:55 AM
With these it helps I am trying to return the value of the method but the loop is throwing an error because the return has to be in the method body not in the loop. I am using system.out.println and it is works but I want to use return instead. , You can obviously return from the for loop.
code :
public String getFileInformation() throws IOException {   
 try{
    String file;
    file = "tra.srt";
    Charset charset = Charset.defaultCharset();
    Path path = Paths.get(file);
    BufferedReader reader = Files.newBufferedReader(path, charset);
    System.out.printf("Lines from %s:%n",file);
    String line;

    while((line = reader.readLine()) != null) {
    if (line.indexOf(':') != -1 && line.indexOf(',') != -1 && line.indexOf('0') != -1) { 
    return line.substring(0, 12); 
    }
    }
    }catch(FileNotFoundException ex){
    System.err.println(ex);
    }

    return "";
}
In ruby how can i return values from a while loop inside method without closing the method iself ?

In ruby how can i return values from a while loop inside method without closing the method iself ?


By : user3714610
Date : March 29 2020, 07:55 AM
I hope this helps . You can use a yield statement or a proc to take the value in the loop and do whatever you want with it:
code :
def yielder
  i = 5
  while i > 0 do 
    puts i
    i -= 1
    yield i
  end
end

yielder {|i| puts "returning the value of #{i}"  }
How to use a for loop inside a return method?

How to use a for loop inside a return method?


By : Brian Stack
Date : March 29 2020, 07:55 AM
Hope this helps There are two aspects to this question.
The first aspect is that the Java compiler is telling you that it "thinks" that there are ways for your method to end without doing an explicit return.
shadow
Privacy Policy - Terms - Contact Us © voile276.org