While and For Loops Comments


  • this is crazy hard to me..

  • I typed in the exact code as the answer and still get a compile error

  • @Billy, looking at your submission, I see the boilerplate code has been changed, which causes a compile error. Reset the code and try again. You only need to put code where it says //your code here.

  • how do i remove the cheat mark my submission was the exact answer :/

  • @Jason, sorry there's no way (currently) to remove the cheat once the cheat button has been clicked.

  • yes this course is very good idea but is should be motivated by java tutorials like beginner ,intermediate,advanced

  • hey im sorry but im still stuck in this on challenge everything looks perfect but i'm still getting errors please help..

  • @Jason, you want to increase the iterator each time. For example, to print the numbers from 1 through 10, you could create a loop like this:

    for(int i=1; i<= 10; i=i+1){

    You need to do that to go from a to b instead.

  • I love the random quotes ♥

  • why is mine not working!!!

  • @Robert, make sure to declare any variable you use, even if it's just used as a loop index.

  • examples are simple and question are vary hard to understand

  • I like this

  • I do understand the While Loop and the example about wanting to repeat something 10 times, but I have a question ( quite stupid really but I just wanna make sure even though I know what is correct xD )
    So If we have
    { int index = 1;
    while(index <= 10){
    index = index + 1
    so now after executing this program the index will at sometime be 2 3 4 5 6 7 8 9 and in the end 10.
    Does this mean that after every time the code is executed the { int index = 1 } changes to 2 3 4 5 6 7 8 9 or 10 from the "index = index + 1" ?
    I know it does but does that appear in the "int index = ?"

  • @Adhurim, "int index=1" is outside the while loop, so it is executed only 1 time.

  • I really was tempted to click the hint for this one but I sat there and thought about the ways to make it work. I still have trouble with the for loop but by just setting int i = a would have been so simple. Oh well I'm glad I got it to work with the while loop but I should avoid it because of the possibility of errors.

  • I did that and although it is correct but I should think of simpler way as the model answer :D :
    public static void doStuff(int a, int b){
    int tmp = a;
    for (int i = 0 ; i< b-a+1;i++)

            tmp= tmp+1;
  • Yeah this one is tough. There should be an explanation of how to include multiple indexes in the first part of the for condition. Do you just use the & and also there is no explanation on how to printout inclusive information i.e. 1-5

  • Are we supposed to solve with the while loop or the "for" loop?

  • it says error:for(int i=a;i<=b;i+1){
    not a statement ^

  • it says error:for(int i=a;i<=b;i+1){
    not a statement ^

  • you have to put: i = i+1; or you can do an abreviation, like i++;

  • This is a great course. I am more comfortable with Java now, and it has only been 30 minutes.

  • int kq=0;
        for(int i=0;kq<b;i=i+1){
  • Here's the easiest solution:

    for (a=a, b=b; a <= b; a++){

  • yeah i have the same thing but different variables ( i used n) and it's not working.

  • while (a <= b) {

  • import java.util.Scanner;
    public class Main {
    public static void main(String[] args){

        Scanner input = new Scanner (System.in);
        System.out.print("Enter 1st number: ");
  • for the for loop challenge:

    for (int i=a; i<=b;i++) {
    printNum (i);

    this basically assigns i as being a for the first time since a is less than b; the condition is to display including

  • for (int i = a; i <= b; i++){

  • just replace all the code with:
    import java.util.Scanner;
    public class Main {

    public static void doStuff(int a, int b){

    long x= a;
    System.out.print(x+" ");
    x = x + 1;

  • Can I use While loop for the problem code above?

  • The only issue I had was thinking that he wanted actual numbers, then I realized that this is a module that gets called rather than core code. Oops.

  • i did the right code but the part that was already done further in the code was wrong. help me?
    public static void printNum(int x){
    system.out.print (x+"");
    it says illegal start of expression.

  • I think you need to be careful not to add extra curly braces or remove existing ones.

  • i did. i even reset the page and re wrote the code

  • i am confusion

  • I like this site :DD

  • huthtiuhithruhriurutrrihrwuerwuuherwhuewuhrwwwhutwhuwtwthuwuhwwetuewhewherihuerwihuweiuhwetuhiuhweiuhweuheuhweuhweuweiuuhiguwuuwgewuewgugewuwgueugwuhewuhwfuhuewuwguhhuueguwuhgwgwuegueghuegwupoohuguhgrughurwuhghuruhrwurhwhrhowhguhwoprugruowhwiphrwuogugrwurhrguwgwghughurwhuuorwhuhuwhgurgwugugrwuuwuphrwpuruhuwrhugrhgwhugrghughgurh7guhe7rguyher7h7uteiyhtyeu5yitgyhrueyhuheuighiuerhgiurhu

Contact Us
Sign in or email us at [email protected]