Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualMathew Bergen

Posted 12 January 2013 - 02:24 AM

The code for the for loop will be the same but here:

 

 

 
//imported crap and other code
 
Scanner scan = new Scanner(System.in);
 
int numLoops;
 
System.out.print("How many loops?");
numLoops = scan.nextInt();
 
for(int i = 0; i < numLoops; ++i){
       
//do whatever you need to and loop as many times as the user entered for numLoops
}
 

 

 

you can do the same thing with a while loop (or do while), but the for loop has everything working in one line, where the while loops will take a couple.

 

Hope this helps smile.png


#1Mathew Bergen

Posted 12 January 2013 - 02:23 AM

The code for the for loop will be the same but here:

 

 
//imported crap and other code
 
Scanner scan = new Scanner(System.in);
 
int numLoops;
 
System.out.print("How many loops?");
numLoops = scan.nextInt();
 
for(int i = 0; i != numLoops; ++i){
       
//do whatever you need to and loop as many times as the user entered for numLoops
}
 

 

you can do the same thing with a while loop (or do while), but the for loop has everything working in one line, where the while loops will take a couple.

 

Hope this helps :)


PARTNERS